Discount bounded loops in Kotlin; split scaling from repeating - #88
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).