Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Jun 13, 2025

Lazy deserialization return NodeArrays which deserialize their contents lazily, instead of plain JS arrays.

program.body.find(stmt => stmt.type === 'ImportDeclaration') now only deserializes the nodes up until first ImportDeclaration, rather than deserializing every statement in the program into an array, and then searching it. Similarly, getting program.body.length does not deserialize any nodes, and all other array methods are similarly optimized.

Also provide an optimized iterator for the common case of:

for (const stmt of program.body) {
  doStuff(stmt);
}

@github-actions github-actions bot added A-ast-tools Area - AST tools C-performance Category - Solution not expected to change functional behavior, only performance labels Jun 13, 2025
Copy link
Member Author


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.

@overlookmotel overlookmotel marked this pull request as ready for review June 13, 2025 16:43
@overlookmotel overlookmotel changed the title perf(napi): lazily deserialize Vecs perf(napi/parser): lazily deserialize Vecs Jun 13, 2025
@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Jun 13, 2025
Copy link
Member Author

overlookmotel commented Jun 13, 2025

Merge activity

Lazy deserialization return `NodeArray`s which deserialize their contents lazily, instead of plain JS arrays.

`program.body.find(stmt => stmt.type === 'ImportDeclaration')` now only deserializes the nodes up until first `ImportDeclaration`, rather than deserializing every statement in the program into an array, and then searching it. Similarly getting `program.body.length` does not deserialize any nodes, and all other array methods are similarly optimized.

Also provide an optimized iterator for the common case of:

```js
for (const stmt of program.body) {
  doStuff(stmt);
}
```
@graphite-app graphite-app bot force-pushed the 06-13-perf_napi_lazily_deserialize_vec_s branch from f3779ee to 60f754e Compare June 13, 2025 16:45
@graphite-app graphite-app bot merged commit 60f754e into main Jun 13, 2025
16 checks passed
@graphite-app graphite-app bot deleted the 06-13-perf_napi_lazily_deserialize_vec_s branch June 13, 2025 16:52
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast-tools Area - AST tools C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants