Skip to content

perf(semantic): reduce index_vec allocation#4266

Closed
Dunqing wants to merge 3 commits intomainfrom
07-15-perf_semantic_reduce_index_vec_allocation
Closed

perf(semantic): reduce index_vec allocation#4266
Dunqing wants to merge 3 commits intomainfrom
07-15-perf_semantic_reduce_index_vec_allocation

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Jul 15, 2024

Combining some SymbolTable fields to the Symbol struct, we can reduce allocating IndexVec. After my changes, I suddenly realized the api is much easier to use now. We no longer need the symbol_id to get the various field value you want, you just need the Symbol

@graphite-app
Copy link
Contributor

graphite-app bot commented Jul 15, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

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

Copy link
Member Author

Dunqing commented Jul 15, 2024

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

Join @Dunqing and the rest of your teammates on Graphite Graphite

@github-actions github-actions bot added A-semantic Area - Semantic A-transformer Area - Transformer / Transpiler labels Jul 15, 2024
@Dunqing Dunqing changed the title perf(parser): speed up parsing octal literals (#4258) perf(semantic): reduce index_vec allocation Jul 15, 2024
@github-actions github-actions bot added the A-linter Area - Linter label Jul 15, 2024
@codspeed-hq
Copy link

codspeed-hq bot commented Jul 15, 2024

CodSpeed Performance Report

Merging #4266 will not alter performance

Comparing 07-15-perf_semantic_reduce_index_vec_allocation (29f251a) with main (639fd48)

Summary

✅ 32 untouched benchmarks

@overlookmotel
Copy link
Member

overlookmotel commented Jul 15, 2024

Interesting that this change from struct-of-arrays to array-of-structs is a gain on benchmarks. However, there is another possible approach to tackling this which may be even better: oxc-project/backlog#11

However, since this PR is a perf gain at present, we could merge it now and attempt oxc-project/backlog#11 later on?

#3318 (comment) is also relevant, though that's pretty tricky - we'd probably need "branded lifetimes" to make it safe.

@Dunqing
Copy link
Member Author

Dunqing commented Jul 15, 2024

Interesting that this change from struct-of-arrays to array-of-structs is a gain on benchmarks. However, there is another possible approach to tackling this which may be even better: oxc-project/backlog#11

However, since this PR is a gain at present, we could merge it now and attempt oxc-project/backlog#11 later on?

This PR is just an attempt at my guess, I'm not sure we want to merge it. I know you will be optimizing the whole semantic, and you probably have further improvements that can be done better. So it's up to you whether to merge it or not!

@Boshen
Copy link
Member

Boshen commented Jul 15, 2024

SoA improves write performance but regresses read performance (notice drop in linter).

I think we should keep SoA unless there is a win across the table + Symbol byte size won't increase in the future.

@Dunqing
Copy link
Member Author

Dunqing commented Jul 15, 2024

SoA improves write performance but regresses read performance (notice drop in linter).

There are further optimizations we can make in linter, Such as we can pass Symbol to run_on_symbol. This may give a small performance boost

I think we should keep SoA unless there is a win across the table + Symbol byte size won't increase in the future.

I realize this, it's something we need to think about

@Dunqing Dunqing force-pushed the 07-15-perf_semantic_reduce_index_vec_allocation branch from dacb316 to c6339de Compare July 15, 2024 13:21
@Dunqing Dunqing force-pushed the 07-15-perf_semantic_reduce_index_vec_allocation branch from c6339de to 29f251a Compare July 15, 2024 13:51
pub scope_id: ScopeId,
/// Pointer to the AST Node where this symbol is declared
pub declaration: AstNodeId,
pub resolved_references: Vec<ReferenceId>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we encapsulate these fields for future flexibility?


#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify), serde(rename_all = "camelCase"))]
pub struct Symbol {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a GetSpan impl.

@Dunqing
Copy link
Member Author

Dunqing commented Jul 19, 2024

Closing this because we tried another better way to improve more in #4328

@Dunqing Dunqing closed this Jul 19, 2024
@Boshen Boshen deleted the 07-15-perf_semantic_reduce_index_vec_allocation branch September 11, 2024 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter A-semantic Area - Semantic A-transformer Area - Transformer / Transpiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants