Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Mar 24, 2025

AstBuilder::move_* methods use TakeIn::take_in (added in #9969) to replace nodes with dummy nodes.

take_in will always generate a dummy in whatever way minimizes the size and number of allocations required.

It would be possible to replace all the move_* methods with a single AstBuilder::take method which is generic over T: TakeIn (#9970). But have opted not to do that, because it's useful to be able to see in calling code what type of node is being replaced.

Some nodes are quite expensive to create a dummy for (e.g. Declaration and Function require allocating 56 bytes into arena, ArrowFunctionExpression allocates 128 bytes in 2 separate allocations), so it's useful to see where we're doing that, so we can try to replace them with cheaper operations e.g. replacing an Expression or Statement instead (only 8 bytes). We also want to avoid inadvertently adding further expensive take_in calls, which a blanket AstBuilder::take method would make it easy to do.

Copy link
Member Author

overlookmotel commented Mar 24, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added A-ast Area - AST C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Mar 24, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 24, 2025

CodSpeed Instrumentation Performance Report

Merging #10001 will not alter performance

Comparing 03-24-refactor_ast_astbuilder_move__methods_use_takein_ (5f45005) with main (b93c394)

Summary

✅ 33 untouched benchmarks

@overlookmotel overlookmotel marked this pull request as ready for review March 24, 2025 06:57
@overlookmotel overlookmotel force-pushed the 03-24-refactor_ast_astbuilder_move__methods_use_takein_ branch from 9f70792 to 5b79ba7 Compare March 24, 2025 10:19
@overlookmotel overlookmotel force-pushed the 03-22-feat_allocator_takein_trait branch from 8c4fd76 to 24b0e8a Compare March 24, 2025 10:19
@overlookmotel overlookmotel requested a review from Boshen March 24, 2025 10:29
@graphite-app graphite-app bot changed the base branch from 03-22-feat_allocator_takein_trait to graphite-base/10001 March 24, 2025 10:30
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Mar 24, 2025
Copy link
Member

Boshen commented Mar 24, 2025

Merge activity

  • Mar 24, 6:38 AM EDT: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Mar 24, 6:38 AM EDT: A user added this pull request to the Graphite merge queue.
  • Mar 24, 6:56 AM EDT: A user merged this pull request with the Graphite merge queue.

@graphite-app graphite-app bot changed the base branch from graphite-base/10001 to main March 24, 2025 10:48
`AstBuilder::move_*` methods use `TakeIn::take_in` (added in #9969) to replace nodes with dummy nodes.

`take_in` will always generate a dummy in whatever way minimizes the size and number of allocations required.

It would be possible to replace all the `move_*` methods with a single `AstBuilder::take` method which is generic over `T: TakeIn` (#9970). But have opted not to do that, because it's useful to be able to see in calling code what type of node is being replaced.

Some nodes are quite expensive to create a dummy for (e.g. `Declaration` and `Function` require allocating 56 bytes into arena, `ArrowFunctionExpression` allocates 128 bytes in 2 separate allocations), so it's useful to see where we're doing that, so we can try to replace them with cheaper operations e.g. replacing an `Expression` or `Statement` instead (only 8 bytes). We also want to avoid inadvertently adding further expensive `take_in` calls, which a blanket `AstBuilder::take` method would make it easy to do.
@graphite-app graphite-app bot force-pushed the 03-24-refactor_ast_astbuilder_move__methods_use_takein_ branch from 5b79ba7 to 5f45005 Compare March 24, 2025 10:49
@graphite-app graphite-app bot merged commit 5f45005 into main Mar 24, 2025
28 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 24, 2025
@graphite-app graphite-app bot deleted the 03-24-refactor_ast_astbuilder_move__methods_use_takein_ branch March 24, 2025 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants