-
-
Notifications
You must be signed in to change notification settings - Fork 794
fix: only flag object assign in accumulators, if it is allocating a new object for each iter #7078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: only flag object assign in accumulators, if it is allocating a new object for each iter #7078
Conversation
… object on every assignment biomejs#6675
…ing new keyword to allocate target objects
🦋 Changeset detectedLatest commit: 984ea89 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
CodSpeed Performance ReportMerging #7078 will not alter performanceComparing Summary
Footnotes
|
|
Thank you @emilyinure, there are a couple of things to address:
|
|
@emilyinure any updates? |
WalkthroughThe PR adjusts the no-accumulating-spread lint: Object.assign argument parsing now requires the first argument to be a composite literal ( Suggested reviewersarendjr Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
🔇 Additional comments (1)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
crates/biome_js_analyze/tests/specs/performance/noAccumulatingSpread/invalid.jsonc.snapis excluded by!**/*.snap
📒 Files selected for processing (4)
.changeset/wet-jeans-repair.md(1 hunks)crates/biome_js_analyze/src/lint/performance/no_accumulating_spread.rs(2 hunks)crates/biome_js_analyze/tests/specs/performance/noAccumulatingSpread/invalid.jsonc(1 hunks)crates/biome_js_analyze/tests/specs/performance/noAccumulatingSpread/valid.jsonc(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Test Node.js API
- GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
- GitHub Check: Documentation
- GitHub Check: Test (depot-ubuntu-24.04-arm-16)
- GitHub Check: Test (depot-windows-2022-16)
- GitHub Check: Bench (biome_js_analyze)
- GitHub Check: Check Dependencies
- GitHub Check: Lint project (depot-windows-2022)
- GitHub Check: Bench (biome_js_formatter)
- GitHub Check: Bench (biome_js_parser)
- GitHub Check: autofix
🔇 Additional comments (4)
crates/biome_js_analyze/src/lint/performance/no_accumulating_spread.rs (2)
208-227: LGTM! The logic correctly identifies allocating patterns.The updated argument extraction logic properly distinguishes between:
- In-place mutation:
Object.assign(acc, bar)→ first arg is identifier, returns None (not flagged)- New allocation:
Object.assign({}, acc, bar)→ first arg is object literal, checks second arg as reference (flagged)The implementation correctly handles edge cases like insufficient arguments by using the
?operator throughout the iterator chain.
46-64: LGTM! Documentation examples align with the new behavior.The updated examples correctly demonstrate:
- Invalid:
Object.assign([], acc, val)creates a new array each iteration- Valid:
Object.assign(acc, val)mutates the accumulator in-placecrates/biome_js_analyze/tests/specs/performance/noAccumulatingSpread/valid.jsonc (1)
22-36: LGTM! Comprehensive test coverage for valid in-place mutations.The test cases correctly cover all combinations:
- Array and Object accumulators
- Arrow and block return styles
- Both
reduceandreduceRightAll patterns use
Object.assign(acc, bar)which mutates the accumulator in-place and should not be flagged.crates/biome_js_analyze/tests/specs/performance/noAccumulatingSpread/invalid.jsonc (1)
35-57: LGTM! Thorough test coverage for allocating patterns.The test cases correctly demonstrate the problematic patterns that allocate a new object/array on each iteration:
Object.assign({}, acc, bar)- new object literalObject.assign([], acc, bar)- new array literalObject.assign(new Array(1), acc, bar)- new array via constructorThese patterns all cause O(n²) time complexity and should be flagged by the rule.
f027d8f to
b69596a
Compare
b69596a to
d1df564
Compare
Updated tense usage at the beginning of changeset, linked back to issue. Moved examples to the inside of codeblocks Explains which cases aren't caught anymore and which are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
.changeset/wet-jeans-repair.md (1)
5-8: Minor punctuation improvement.The description reads well but could be slightly clearer. The transition from "each iteration." to "Previously" might benefit from a stronger conjunction or restructuring:
-Fixed [#6675](https://github.com/biomejs/biome/issues/6675): Only flags +Fixed [#6675](https://github.com/biomejs/biome/issues/6675): now only flags noAccumulatingSpread on Object.assign when a new object is being allocated on -each iteration. Previously all cases using Object.assign with reduce parameters +each iteration. Before, all cases using Object.assign with reduce parameters were warned despite not making new allocations.This makes the before/after contrast more explicit.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.changeset/wet-jeans-repair.md(1 hunks)
🧰 Additional context used
🪛 LanguageTool
.changeset/wet-jeans-repair.md
[uncategorized] ~7-~7: Possible missing comma found.
Context: ...t is being allocated on each iteration. Previously all cases using Object.assign with redu...
(AI_HYDRA_LEO_MISSING_COMMA)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: Test (depot-ubuntu-24.04-arm-16)
- GitHub Check: Test (depot-windows-2022-16)
- GitHub Check: Documentation
- GitHub Check: Lint project (depot-windows-2022)
- GitHub Check: Check Dependencies
- GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
- GitHub Check: autofix
- GitHub Check: End-to-end tests
- GitHub Check: Bench (biome_js_parser)
- GitHub Check: Bench (biome_js_formatter)
- GitHub Check: Bench (biome_js_analyze)
- GitHub Check: Test Node.js API
Remove example that contains syntax error Update grammer
Co-authored-by: Carson McManus <[email protected]>
…ew object for each iter (biomejs#7078) Co-authored-by: Carson McManus <[email protected]>
…ew object for each iter (biomejs#7078) Co-authored-by: Carson McManus <[email protected]>
… object on every assignment
Closes #6675
Summary
Accumulating Object.Assign isn't inherently bad as not all calls create new objects which result in the O(n*n) memory usage.
#6675
#5277
Test Plan
Testing shows that only when we are creating a new object every iteration, and assigning to it from the accumulator, it gets flagged