Skip to content

perf(linter/plugins): create AST nodes with Object.create instead of __proto__ literals - #27816

Merged
overlookmotel merged 1 commit into
oxc-project:mainfrom
wan9chi:perf/oxlint-ast-object-create
Oct 29, 2026
Merged

overlookmotel merged 1 commit into
oxc-project:mainfrom
wan9chi:perf/oxlint-ast-object-create

Conversation

@wan9chi

@wan9chi wan9chi commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

oxlint's raw transfer deserializer creates every AST node as an object literal with __proto__: NodeProto (for the lazy loc getter). V8 creates such object literals on a slow path: it builds a plain object, then changes its prototype with a runtime call.

This PR changes the raw transfer codegen (LocFieldAdder in tasks/ast_tools/src/generators/raw_transfer.rs) to create nodes with Object.create(NodeProto) followed by property assignments:

// `main`
node = (parent = { __proto__: NodeProto, type: "CallExpression", callee: null, /* ... */ });

// This PR
node = (parent = (node$0 = Object.create(NodeProto), node$0.type = "CallExpression", node$0.callee = null, /* ... */ node$0));

Nodes keep the same prototype, own properties, property order and attributes. napi/parser's deserializers are unaffected.

Benchmark

Deserialization time when linting vscode @ 3db52ff (15,122 files, 53.4M AST nodes) with a single JS rule which visits DebuggerStatement (to make sure deserialization isn't eliminated as dead code). Apple M4 Pro, Node 26.5.0, release build.

Measured by timing each deserializeProgramOnly call in initAst with performance.now() (local instrumentation, not part of this PR), summed over all 15,086 deserialized files. Medians of 5 interleaved runs, after a warmup run.

Deserialize
main 4.49 s
This PR 0.91 s (4.9Γ— faster)

AI disclosure: this PR was written with AI assistance (Claude Code).

πŸ€– Generated with Claude Code

@wan9chi
wan9chi marked this pull request as draft October 16, 2026 07:01
@github-actions github-actions Bot added A-linter Area - Linter (oxlint): rules, config, diagnostics, fixes. Add L-* labels for details A-cli Area - oxlint / oxfmt common CLI behavior: flags, ignore files, oxc_config A-ast-tools Area - AST code generation tooling, tasks/ast_tools L-js-plugins Linter > JS plugins (ESLint-compatible plugin API) labels Oct 16, 2026
@wan9chi
wan9chi force-pushed the perf/oxlint-ast-object-create branch from bf5618b to 9e15f03 Compare October 16, 2026 07:07
@wan9chi
wan9chi marked this pull request as ready for review October 16, 2026 07:10
@overlookmotel overlookmotel self-assigned this Oct 16, 2026
@overlookmotel

Copy link
Copy Markdown
Member

WTF?? __proto__: NodeProto was a late addition. Previously all nodes were plain objects, and we didn't see anything like a 5x slow-down when we made that change.

I'm on holiday at the moment but will look at it when I get back.

@wan9chi

wan9chi commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

WTF?? __proto__: NodeProto was a late addition. Previously all nodes were plain objects, and we didn't see anything like a 5x slow-down when we made that change.

I'm on holiday at the moment but will look at it when I get back.

According to claude it seems to be a regression in v8:

Cause

V8 13 changed how { __proto__: X, ... } literals are created, as part of moving prototype transitions to the front of the transition tree. It was enabled by default in Nov 2024 and the old behaviour was removed in Jan 2026. The side effect is that creating an object literal with __proto__ got much more expensive. It's still a fast-mode object with a stable map; only creation got slower.

Node 22 (V8 12.4) and Node 23 (V8 12.9) have the old behaviour; Node 24 (V8 13.6) and Node 26 (V8 14.6) have the new one.

#14552 merged on 2025-10-13 when .node-version was 22.20.0, and the ~20% you measured matches what we get on Node 22. The repo moved to Node 24 two weeks later (#14982) and this was never re-measured.

Evidence

Node 23 is the one version where the change is off by default but can still be turned on with --move-prototype-transitions-first, so this is the same binary and same code with only the flag flipped. Microbenchmark creating deserializer-shaped nodes (~40 node types, each with its own shape):

Node 23 plain literal { __proto__: NodeProto, ... } Object.create(NodeProto) + assignments
flag off (default) 55 ns/node 164 ns/node 70 ns/node
flag on 55 ns/node 603 ns/node 70 ns/node

@overlookmotel

Copy link
Copy Markdown
Member

Well holy crap! I guess this is what happens when you don't have continuous benchmarking.

Thanks so much for finding this, and for rooting out the cause.

@overlookmotel
overlookmotel force-pushed the perf/oxlint-ast-object-create branch from 9e15f03 to 0ff05cf Compare October 29, 2026 01:05
@overlookmotel

Copy link
Copy Markdown
Member

Squashed to 1 commit, rebased on latest main, and regenerated deserializer to fix merge conflicts. Will merge as soon as CI passes.

@overlookmotel
overlookmotel merged commit 481b638 into oxc-project:main Oct 29, 2026
31 checks passed
graphite-app Bot pushed a commit that referenced this pull request Oct 29, 2026
Follow on after #27816.

Make the `oxc_ast_tools` code a bit more efficient - allocating less strings and avoiding repeated hashing of `Ident`s. Also remove the unnecessary extra `allocator` field on `LocFieldAdder` - the `AstBuilder` it contains already contains the `&Allocator` reference.

Does not alter the generated code, only makes generating it a little faster.
@wan9chi
wan9chi deleted the perf/oxlint-ast-object-create branch October 29, 2026 02:01
graphite-app Bot pushed a commit that referenced this pull request Nov 2, 2026
# Oxlint
### πŸš€ Features

- 004647a track_memory_allocs: Add allocation tracking for linter rules (#28470) (Cam McHenry)
- 419c1b0 linter: Add allow and allowPattern options to react/capitalized-calls (Christian Vuerings)

### πŸ› Bug Fixes

- a205cd3 linter/eslint/no-control-regex: Detect raw control characters (#28548) (camc314)
- 7c65777 linter/unicorn/prefer-global-this: Align typeof and worker API handling (#28549) (camc314)
- 987d5f1 linter/unicorn/no-invalid-fetch-options: Avoid treating unknown methods as GET (#28547) (camc314)
- e234dc8 linter/unicorn/no-useless-error-capture-stack-trace: Move to suspicious category (#28545) (camc314)
- b3dc411 linter/typescript/no-non-null-asserted-nullish-coalescing: Move to suspicious category (#28546) (camc314)
- cb64638 regular_expression: Reject incomplete Unicode atom escapes (#28448) (Boshen)
- c67167e linter: Only run React Compiler rules on files with top-level components or hooks (Boshen)
- 4c9d5aa linter: Treat Reanimated shared values as ref-like in React Compiler rules (Boshen)
- 61fe2af linter/react: Ignore impure calls in async components in react/purity (Rahul Kashyap)
- ed7df7d ast/estree: Include comments in TS Program span (#28326) (camc314)
- 31cbe37 linter: Make gitlab fingerprints unique per diagnostic (#28307) (camc314)

### ⚑ Performance

- bb947dc linter: Skip numeric separator formatting for short integers (#28485) (Cam McHenry)
- 1043dfa linter: Avoid collecting prefer-const binding identifiers (#28484) (Cam McHenry)
- 7c93eef linter: Reduce branches-sharing-code scratch allocations (#28483) (Cam McHenry)
- c0065fd linter: Allocate escape-case replacements only when needed (#28482) (Cam McHenry)
- d837414 linter: Lazily normalize capitalized-comments text (#28481) (Cam McHenry)
- 6baaad6 linter: Avoid no-var binding identifier allocations (#28480) (Cam McHenry)
- 882053b linter: Skip read-only parameters in no-param-reassign (#28479) (Cam McHenry)
- 92deebf linter: Reduce no-unmodified-loop-condition allocations (#28478) (Cam McHenry)
- f01d52d linter: Reduce no-duplicate-case allocations (#28477) (Cam McHenry)
- 6a72d84 linter: Reduce no-dupe-class-members allocations (#28476) (Cam McHenry)
- 77599ef linter: Reduce no-this-before-super allocations (#28475) (Cam McHenry)
- 2ea9f58 linter/no-dupe-else-if: Use smallvec to reduce allocs (#28474) (Cam McHenry)
- 69f0204 linter/react/rules-of-hooks: Reduce allocs (#28473) (Cam McHenry)
- b138c20 linter: Reduce allocs in no-dupe-keys (#28472) (Cam McHenry)
- 6f3e982 linter: Avoid operator allocations in no-useless-length-check (#28471) (Cam McHenry)
- fd68928 react-compiler: Skip passes lint does not need (Yagiz Nizipli)
- 224f4dd linter/eslint/sort-keys: Reserve initial capacity for string (#27624) (Cam McHenry)
- e4e01a3 linter/import/no-cycle: Compare visited modules by absolute resolved path (#27517) (Cam McHenry)
- 741b29b linter/import/no-cycle: Cache sorted module record snapshots (#27516) (Cam McHenry)
- 20022bb linter/import/no-cycle: Reuse traversal buffers between imports (#27481) (Cam McHenry)
- fd5edb7 linter/import/no-cycle: Reuse module records in diagnostic stack (#27480) (Cam McHenry)
- 73e877c linter/import/no-cycle: Don't allocate paths already seen (#27478) (Cam McHenry)
- 1515d53 linter/react/forward-ref-uses-ref: Narrow forward-ref-uses-ref dispatch (#28367) (Cam McHenry)
- ee51c01 linter/react/no-string-refs: Narrow AST dispatch (#28366) (Cam McHenry)
- bbfd692 linter/react/no-children-pop: Narrow AST dispatch (#28365) (Cam McHenry)
- a86158b linter/unicorn/prefer-set-size: Narrow AST dispatch (#28364) (Cam McHenry)
- a777fa6 linter/eslint/no-iterator: Narrow member dispatch (#28363) (Cam McHenry)
- bc5e94d linter/eslint/no-extra-boolean-cast: Narrow AST dispatch (#28362) (Cam McHenry)
- 93c6e6d linter/unicorn/no-useless-fallback-in-spread: Narrow AST dispatch (#28361) (Cam McHenry)
- 1a1f66e linter/typescript/no-this-alias: Narrow AST dispatch (#28360) (Cam McHenry)
- b102a91 linter/typescript/no-wrapper-object-types: Index references (#28359) (Cam McHenry)
- dbd8a0b linter/eslint/no-unassigned-vars: Batch by declaration (#28358) (Cam McHenry)
- 1108352 linter/typescript/prefer-as-const: Narrow AST dispatch (#28357) (Cam McHenry)
- d65531f linter/eslint/no-const-assign: Batch by declaration (#28356) (Cam McHenry)
- 1ec9991 linter/oxc/number-arg-out-of-range: Narrow AST dispatch (#28355) (Cam McHenry)
- 7a1243e linter/unicorn/no-invalid-fetch-options: Narrow AST dispatch (#28354) (Cam McHenry)
- 2ab73cc linter/unicorn/no-single-promise-in-promise-methods: Narrow AST dispatch (#28353) (Cam McHenry)
- 483c4c9 linter/eslint/no-compare-neg-zero: Narrow no-compare-neg-zero dispatch (#28352) (Cam McHenry)
- 56c99c6 linter/eslint/no-unsafe-negation: Narrow AST dispatch (#28351) (Cam McHenry)
- 84d974b linter/unicorn/prefer-string-starts-ends-with: Narrow AST dispatch (#28350) (Cam McHenry)
- 142ef4f unicorn: Narrow no-await-in-promise-methods dispatch (#28349) (Cam McHenry)
- a3dc7a2 linter/unicorn/no-await-expression-member: Optimize AST dispatch (#28348) (Cam McHenry)
- 481b638 linter/plugins: Create AST nodes with `Object.create` instead of `__proto__` literals (#27816) (Charles Wang)
# Oxfmt
### πŸ’₯ BREAKING CHANGES

- 296623d oxfmt: [**BREAKING**] Format `parser:html` files by `oxc_formatter_htmlish` (#28273) (Yuji Sugiura)

### πŸš€ Features

- 336b2c1 oxfmt: Support html-in-js templates closing a dynamic tag name (#28389) (Yuji Sugiura)
- 0a42af6 formatter_htmlish: Format end tags of omitted `html`, `head` and `body` (#28388) (Yuji Sugiura)
- 44d8c2b formatter_htmlish: Implement HTML-ish formatter `Html` variant (#28272) (Yuji Sugiura)
- 36e5ddb oxfmt: Add debug span for reading files (#28204) (leaysgur)

### πŸ› Bug Fixes

- dbcc358 formatter: Keep arrow conditional body parens before a leading `function`/`class` (#28710) (Yuji Sugiura)
- fef809a formatter_htmlish: Handle XHTML (#28703) (leaysgur)
- f3dd201 formatter_htmlish: Keep SVG text under `xml:space="preserve"` as written (#28382) (Yuji Sugiura)
- fb3aefa formatter: Keep source parens around html-in-js placeholders past comments (#28381) (Yuji Sugiura)
- e738dae formatter: Quote keys added in an HTML event handler with single quotes (#28380) (Yuji Sugiura)
- 2e7a629 oxfmt: Format HTML in a `<script>` body as an embedded part (#28379) (Yuji Sugiura)
- f00862b formatter: Keep parens around a generic function type in a type assertion (#28173) (vidigoat)
- 9ead5c4 formatter: Handle `this.b` and `super.b` like `foo.b` (#28200) (leaysgur)
- 72a54cf formatter: Break parens of `(a + b)[c]` like `(a + b).c` (#28199) (leaysgur)
- b8f4f34 formatter: Print `x.b` and `x.#b` samely (#28193) (leaysgur)
- 9ddccb7 formatter: Keep parens for private field (#28188) (leaysgur)

### ⚑ Performance

- b6f1ac9 formatter_markdown: Bump parser to 0.0.4 and skip unread work (#28713) (leaysgur)
- 633ee96 formatter_css: Use `u32` spans (#28708) (leaysgur)
- f680ee1 formatter_yaml: Use `multiline` flag for flow scalars (#28707) (leaysgur)
- ff7c203 formatter_css: Avoid repeated scans and allocations in values (#28706) (leaysgur)
- 7cd46cb formatter_htmlish: Search script end tags by `<` in embedded (#28704) (leaysgur)
- 46f8efd formatter_graphql: Print block string lines borrowed from the source (#28701) (leaysgur)
- dce1485 formatter_htmlish: Skip escaping attr values without the chosen quote (#28700) (leaysgur)
- e9392c8 formatter_core: Search line terminators with memchr (#28699) (leaysgur)
- ceb26be formatter_htmlish: Use `char` to escape attr quotes (#28697) (leaysgur)
- 8239dac parser: Replace dragonbox_ecma with zmij_ecma (#28282) (Boshen)

### πŸ“š Documentation

- 303d9e8 formatter: Strengthen `start-token-no-double-parens` rationale (#28711) (Yuji Sugiura)
- a82ce83 oxfmt: Update unclassified divergence (#28685) (Yuji Sugiura)
- 7f18c20 formatter_htmlish: Note `class` and `srcset` are formatted with `embeddedLanguageFormatting: off` (#28465) (Yuji Sugiura)
- 01ed68a oxfmt,formatter_htmlish,formatter: Clean up behavior comments (#28384) (Yuji Sugiura)
- a363c27 formatter_css,formatter_yaml: Point parser citations at AGENTS.md (#28466) (Yuji Sugiura)
- 6586050 formatter_core: Document tab width in text width policy (#28393) (leaysgur)
- 49fbffb formatter_core: Tighten FORMATTER_POLICY (#28206) (leaysgur)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast-tools Area - AST code generation tooling, tasks/ast_tools A-cli Area - oxlint / oxfmt common CLI behavior: flags, ignore files, oxc_config A-linter Area - Linter (oxlint): rules, config, diagnostics, fixes. Add L-* labels for details L-js-plugins Linter > JS plugins (ESLint-compatible plugin API)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants