Skip to content

perf(semantic): store class parents in IndexVec#22659

Closed
camc314 wants to merge 1 commit into
mainfrom
c/05-21-perf_semantic_store_class_parents_in_indexvec
Closed

perf(semantic): store class parents in IndexVec#22659
camc314 wants to merge 1 commit into
mainfrom
c/05-21-perf_semantic_store_class_parents_in_indexvec

Conversation

@camc314

@camc314 camc314 commented May 21, 2026

Copy link
Copy Markdown
Contributor

ClassTable stored parent class links in an FxHashMap<ClassId, ClassId>, but ClassId is dense and allocated by the same table. The parent lookups in pop_class, ancestors, and the super syntax-check path only need direct lookup by ClassId.

This changes parent storage to IndexVec<ClassId, Option<ClassId>>, pushes one parent slot when declaring each class, and reads parents through ClassTable::parent_id.

camc314 commented May 21, 2026

Copy link
Copy Markdown
Contributor 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 changes, fast-track this PR to the front of the merge queue

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.

@camc314 camc314 marked this pull request as ready for review May 21, 2026 20:39
@camc314 camc314 requested a review from Dunqing as a code owner May 21, 2026 20:39
Copilot AI review requested due to automatic review settings May 21, 2026 20:39
@camc314 camc314 force-pushed the c/05-21-perf_semantic_store_class_parents_in_indexvec branch from b54ad38 to 94ae935 Compare May 21, 2026 20:41
@codspeed-hq

codspeed-hq Bot commented May 21, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 57 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing c/05-21-perf_semantic_store_class_parents_in_indexvec (ab047bb) with main (d721ad9)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

binder.ts | 193.08 kB || 41 | 1 || 7076 | 824

kitchen-sink.tsx | 732.90 kB || 3138 | 345 || 100206 | 17853
kitchen-sink.tsx | 732.90 kB || 3138 | 357 || 100206 | 17853

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm i'm not sure about this change actually

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think FxHashMap is good here, as nested classes are not very common in practice. This approach may reallocate a few times more for a lot of None, which may cause a regression because faster access to data does not outweigh these allocation overheads.

Maybe you can try a further optimization to save these unnecessary reallocations by calculating the exact class count in stats, so we can reserve enough space upfront.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I agree. i don't think this is a positive change - lets close

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes class-parent lookups in oxc_semantic by replacing ClassTable’s parent storage from a hash map keyed by ClassId to a dense IndexVec<ClassId, Option<ClassId>>, aligning storage with the fact that ClassId is allocated densely by the same table.

Changes:

  • Replace ClassTable.parent_ids storage from FxHashMap<ClassId, ClassId> to IndexVec<ClassId, Option<ClassId>>.
  • Add ClassTable::parent_id() and route parent traversals (ancestors, pop_class, and check_super) through it.
  • Ensure parent slot and declaration slot stay aligned by pushing one parent entry per declared class (with a debug assertion on index equality).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

File Description
crates/oxc_semantic/src/class/table.rs Switch parent storage to IndexVec and add parent_id() accessor; update ancestors and declare_class to keep vectors aligned.
crates/oxc_semantic/src/class/builder.rs Update class pop logic to use ClassTable::parent_id() instead of direct map access.
crates/oxc_semantic/src/checker/javascript.rs Update super syntax-check logic to use ClassTable::parent_id() for parent traversal.

Comment on lines 49 to 52
#[derive(Debug, Default)]
pub struct ClassTable<'a> {
pub parent_ids: FxHashMap<ClassId, ClassId>,
pub parent_ids: IndexVec<ClassId, Option<ClassId>>,
pub declarations: IndexVec<ClassId, NodeId>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is correct. Can you double check this @camc314 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@graphite-app graphite-app Bot force-pushed the c/05-21-perf_semantic_use_direct_grandparent_lookup_for_ts_type_parameters branch from 37ab523 to 0c22389 Compare May 22, 2026 00:57
@graphite-app graphite-app Bot force-pushed the c/05-21-perf_semantic_store_class_parents_in_indexvec branch from 94ae935 to 7078e0d Compare May 22, 2026 00:57
@graphite-app graphite-app Bot changed the base branch from c/05-21-perf_semantic_use_direct_grandparent_lookup_for_ts_type_parameters to graphite-base/22659 May 22, 2026 04:22
@graphite-app graphite-app Bot force-pushed the c/05-21-perf_semantic_store_class_parents_in_indexvec branch from 7078e0d to 749b0f9 Compare May 22, 2026 04:28
@graphite-app graphite-app Bot force-pushed the graphite-base/22659 branch from 0c22389 to d721ad9 Compare May 22, 2026 04:28
@graphite-app graphite-app Bot changed the base branch from graphite-base/22659 to main May 22, 2026 04:29
@graphite-app graphite-app Bot force-pushed the c/05-21-perf_semantic_store_class_parents_in_indexvec branch from 749b0f9 to ab047bb Compare May 22, 2026 04:29
@camc314 camc314 closed this May 22, 2026
@Boshen Boshen deleted the c/05-21-perf_semantic_store_class_parents_in_indexvec branch May 31, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-semantic Area - Semantic

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants