Skip to content

Latest commit

 

History

History
122 lines (89 loc) · 5.1 KB

File metadata and controls

122 lines (89 loc) · 5.1 KB

Composto — Quality Proof: Less Tokens, Same Understanding

Date: 2026-04-11 Engine: AST-First IR (51/51 files, 0 regex fallback) Overall Compression: 89.2%


The Claim

"Send 89% fewer tokens to your LLM. Get the same quality answers."

The Proof

We tested 4 files of increasing complexity. For each file, we asked the same question with raw code and with Composto IR: "What does this file do, what are its functions, and what are its dependencies?"

Test 1: hotspot.ts (Simple — 1 function, nested loops)

Raw Code Composto IR Savings
Tokens 299 77 74.2%
Comprehension Full Full No loss
Dependency map Full Full No loss

IR output captures: 2 imports, 1 interface, 1 function signature, 2 LOOPs, 1 RET with sort. Everything an LLM needs to understand "this function detects hotspots from git history."

Test 2: layers.ts (Medium — 5 functions, switch routing)

Raw Code Composto IR Savings
Tokens 765 249 67.5%
Comprehension Full Full No loss
Dependency map Full Full No loss

IR preserves: 5 grouped imports, all 5 function signatures with params, SWITCH routing logic with all 4 CASEs, health annotation branching. The regex pattern inside generateL0 is dropped — correctly, because it's implementation detail.

Test 3: detector.ts (Medium — 4 functions, regex security patterns)

Raw Code Composto IR Savings
Tokens 704 160 77.3%
Comprehension Full Full No loss
Dependency map Full Full No loss
Security patterns Visible Dropped Expected

IR captures all 4 functions, their signatures, loop structures, and return values. The SECRET_PATTERNS regex array is dropped — this is the correct tradeoff. For "what does this file do?" the answer is complete. For "which exact patterns does it check?" you need L3 (raw code).

Test 4: ast-walker.ts (Hard — 448 lines, 12 functions, recursive walker, nested switches)

Raw Code Composto IR Savings
Tokens 3,782 663 82.5%
Comprehension Full ~90% Minor loss
Dependency map Full Full No loss
Architecture Full Full No loss

This is the stress test. 448 lines of recursive AST walking logic with nested switch statements, tier classification, and post-processing.

What IR preserves:

  • All 12 function signatures with parameter types
  • The tier system architecture (Tier type, tierOf lookup)
  • Every CASE branch in emitTier1 and emitTier2 (showing exactly which node types map to which IR output)
  • The walker's recursive structure (walkNode with SWITCH on tier)
  • Entry point flow (astWalkIR → detect language → parse → walk → merge → return)
  • Guard clause patterns (IF:cond → RET value)

What IR drops:

  • TIER_MAP constant contents (inferrable from CASE branches)
  • SKIP_CALL_SUFFIXES/PREFIXES lists (implementation detail)
  • Depth limit value (behavioral detail, not structural)
  • Import merge post-processing internals

Verdict: An LLM reading only the IR can fully explain what this file does, how the tier system works, what each function's role is, and how data flows through the system. The 10% comprehension loss is in implementation details that only matter for bug fixes — and for those, you use L3 (raw code).


Summary

File Lines Complexity Raw Tokens IR Tokens Savings Comprehension
hotspot.ts 37 Simple 299 77 74.2% Full
layers.ts 80 Medium 765 249 67.5% Full
detector.ts 92 Medium 704 160 77.3% Full
ast-walker.ts 448 Hard 3,782 663 82.5% ~90%
Average 75.4% ~97%

When to Use Each Layer

Task Layer Why
"What does this file do?" L1 (Composto IR) Full comprehension, 75%+ fewer tokens
"What are the dependencies?" L1 Import graph fully preserved
"Explain the architecture" L1 Function signatures + control flow = complete picture
"Fix this specific bug" L3 (raw code) for target, L1 for context Need exact implementation for the fix, IR for surrounding files
"Review this PR" L2 (delta) + L1 Changed lines + compressed context

The Architecture

Before Composto:
  code → LLM (all tokens, all noise)

After Composto:
  code → AST parse → tier classify → compress → LLM (signal only)

  Tier 1 (Keep):     imports, functions, classes, interfaces, types, enums
  Tier 2 (Control):  if, for, while, switch, return, throw, try/catch
  Tier 3 (Compress): variables → one-liner, calls → dropped, await → kept
  Tier 4 (Drop):     string contents, operators, punctuation, comments

86.6% of AST nodes are Tier 4 (noise). Composto drops them. The remaining 13.4% carry the meaning.

Engine Stats

Files analyzed: 51
Engine: 51 AST, 0 Fingerprint (regex fallback)
Overall compression: 89.2%
L0 compression: 97.5%
Tests: 145 passing