Skip to content

Discount bounded loops in Kotlin; split scaling from repeating - #88

Merged
dejo1307 merged 1 commit into
mainfrom
fix/kotlin-bounded-loop-discounting
Jul 10, 2026
Merged

Discount bounded loops in Kotlin; split scaling from repeating#88
dejo1307 merged 1 commit into
mainfrom
fix/kotlin-bounded-loop-discounting

Conversation

@dejo1307

Copy link
Copy Markdown
Collaborator

The Kotlin extractor emitted a raw loop_depth and no scaling_loop_depth, so perf.scalingDepth() silently substituted the raw value and a constant-count loop inflated the Big-O exponent at full confidence. Kotlin now classifies each loop and emits scaling_loop_depth and calls_in_scaling_loop, joining the Go/Python/TypeScript convention.

Fixing that surfaced a second defect in Go, Python and TypeScript. A single "bounded" predicate drove two different questions: whether a loop adds a factor of n, and whether its body repeats. An infinite loop answers those differently — for {} adds no exponent, but a chain walk inside one issues a query per level. Both are now tracked:

scaling = grows with the input -> scaling_loop_depth
repeats = non-constant trip count -> calls_in_scaling_loop

calls_in_scaling_loop is also emitted whenever calls_in_loop is, even when empty, because the consumer keys off the prop's presence; an omitted key read as "never computed" and fell back to the unfiltered call set. The two defects masked each other — fixing only the emptiness would have dropped true-positive N+1 findings on infinite loops, with green tests and no golden diff, since no fixture covered it.

perf.go needs no logic change; two of its comments described the bug as if it were the design and are corrected.

cacheVersion v97 -> v99, with cachecov entries and golden fixtures pinning all three loop classes in four languages (Ruby and Swift as inline-discount controls).

The Kotlin extractor emitted a raw loop_depth and no scaling_loop_depth,
so perf.scalingDepth() silently substituted the raw value and a
constant-count loop inflated the Big-O exponent at full confidence.
Kotlin now classifies each loop and emits scaling_loop_depth and
calls_in_scaling_loop, joining the Go/Python/TypeScript convention.

Fixing that surfaced a second defect in Go, Python and TypeScript. A
single "bounded" predicate drove two different questions: whether a loop
adds a factor of n, and whether its body repeats. An infinite loop
answers those differently — `for {}` adds no exponent, but a chain walk
inside one issues a query per level. Both are now tracked:

  scaling  = grows with the input    -> scaling_loop_depth
  repeats  = non-constant trip count -> calls_in_scaling_loop

calls_in_scaling_loop is also emitted whenever calls_in_loop is, even
when empty, because the consumer keys off the prop's presence; an
omitted key read as "never computed" and fell back to the unfiltered
call set. The two defects masked each other — fixing only the emptiness
would have dropped true-positive N+1 findings on infinite loops, with
green tests and no golden diff, since no fixture covered it.

perf.go needs no logic change; two of its comments described the bug as
if it were the design and are corrected.

cacheVersion v97 -> v99, with cachecov entries and golden fixtures
pinning all three loop classes in four languages (Ruby and Swift as
inline-discount controls).
@dejo1307
dejo1307 merged commit 5f20213 into main Jul 10, 2026
4 checks passed
@dejo1307
dejo1307 deleted the fix/kotlin-bounded-loop-discounting branch July 17, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant