Add PERF006 rule and fix perf_lint warnings across codebase#2318
Merged
Conversation
Detect push, push_clone, emplace on arrays inside loops without a preceding reserve() call. Uses propagateWrite-style expression chain walking to trace through field access (self.items), index, deref, cast to find the root variable and check scope. Key features: - Field path tracking: reserve(t.a, N) does not suppress warning for t.b - Conditional suppression: push inside if/else is not flagged - Closure suppression: push in lambda/block inside loop is not flagged - fromGeneric-based function matching for builtin generics Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Detect push, push_clone, emplace on arrays inside loops without a preceding reserve() call. Uses propagateWrite-style expression chain walking (ExprField, ExprAt, ExprCast, etc.) to trace through field access chains and find the root variable. Key features: - Field path tracking: reserve(t.a, N) does not suppress warning for t.b - Known-length loop detection: only warns in for loops with known-length sources (array, range, fixed_array, string), not iterators/generators - While loops always warn (user controls the bound) - Conditional suppression: push inside if/else is not flagged - Closure suppression: push in lambda/block inside loop is not flagged - inferStack reporting: warnings on generic instances show instantiation chain - fromGeneric-based function matching for builtin generics Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add reserve() before push/emplace loops in 15 daslib files: aot_standalone, apply, ast_cursor, coverage, dap, das_source_formatter, daspkg, debug, decs_state, json, match, rst, spoof, templates, typemacro_boost. Fix json_boost JV generic: reserve for is_array/is_dim sources. Fix templates.das: store hashes in array, build_string after loop. Fix perf_lint.das: use build_string for inferStack message (require strings). Improve PERF006 accuracy: - While loops no longer trigger (bound is runtime-dependent, can't reserve) - Update test file with while loop as good pattern Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tiny fixed-size loop (4 hex chars max), reserve adds overhead for no benefit. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Pre-allocate vertex and index arrays in gen_sphere and gen_cylinder based on computed sizes. Fixes PERF006 warnings. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- linq: reserve in zip_impl/zip3_impl (min of source lengths, require math) - json_boost: reserve in from_JV array deserialization - soa: reserve in generated from_array and to_array functions - geom_gen: reserve vertices/indices in gen_sphere/gen_cylinder - arcanoid: reserve in gen_rounded_cube geometry - gameplay/test_gameplay: reserve in build_double_deck, test hand array - 34_decs tutorial: reserve in entity creation loop Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
push/push_clone/emplaceon arrays inside for loops without a precedingreserve()character_at(s, 0)and suggestsfirst_character(s), PERF003 now fires inside closuresPERF006 — push/emplace in loop without reserve()
Detects
push,push_clone,emplaceon arrays inside for loops with known-length sources (array, range, fixed_array, string) without a precedingreserve().reserve(t.a, N)does not suppress warning fort.bif/elsenot flaggedTest plan