Skip to content

Comments

perf(semantic): use FxHashMap instead of IndexMap#4228

Closed
Dunqing wants to merge 1 commit intomainfrom
07-12-perf_semantic_use_fxhashmap_instead_of_indexmap
Closed

perf(semantic): use FxHashMap instead of IndexMap#4228
Dunqing wants to merge 1 commit intomainfrom
07-12-perf_semantic_use_fxhashmap_instead_of_indexmap

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Jul 12, 2024

No description provided.

@graphite-app
Copy link
Contributor

graphite-app bot commented Jul 12, 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.

@github-actions github-actions bot added the A-semantic Area - Semantic label Jul 12, 2024
@codspeed-hq
Copy link

codspeed-hq bot commented Jul 12, 2024

CodSpeed Performance Report

Merging #4228 will improve performances by 3.37%

Comparing 07-12-perf_semantic_use_fxhashmap_instead_of_indexmap (f1e78e8) with main (81ed588)

Summary

⚡ 1 improvements
✅ 31 untouched benchmarks

Benchmarks breakdown

Benchmark main 07-12-perf_semantic_use_fxhashmap_instead_of_indexmap Change
transformer[pdf.mjs] 50 ms 48.4 ms +3.37%

@overlookmotel
Copy link
Member

overlookmotel commented Jul 12, 2024

I did wonder why we were using IndexMap, as iteration order isn't important. Is there any reason it was chosen?

@Dunqing Dunqing force-pushed the 07-12-perf_semantic_use_fxhashmap_instead_of_indexmap branch from 4f2efd6 to 3234279 Compare July 12, 2024 11:56
@github-actions github-actions bot added the A-linter Area - Linter label Jul 12, 2024
@Dunqing
Copy link
Member Author

Dunqing commented Jul 12, 2024

I did wonder why we were using IndexMap, as iteration order isn't important. Is there any reason it was chosen?

I don't know why. I just found it slower than FxHashMap.

@Dunqing
Copy link
Member Author

Dunqing commented Jul 12, 2024

We got 1%~3% performance improvement and removed 1 dependency!
image

@Dunqing Dunqing marked this pull request as ready for review July 12, 2024 12:07
@Dunqing Dunqing force-pushed the 07-12-perf_semantic_use_fxhashmap_instead_of_indexmap branch from 3234279 to f1e78e8 Compare July 12, 2024 12:07
@Dunqing Dunqing changed the title perf(semantic): use FxHashMap instead of indexmap perf(semantic): use FxHashMap instead of IndexMap Jul 12, 2024
@Boshen
Copy link
Member

Boshen commented Jul 12, 2024

f8828db

The mangler is sensitive to binding position.

@Boshen Boshen marked this pull request as draft July 12, 2024 12:39
@overlookmotel
Copy link
Member

The mangler is sensitive to binding position.

Ah ha. So that's why IndexMap.

But... binding insertion order and position don't always align. They will if the AST comes direct from the parser. But what if a transform alters e.g. function params? Then you could end up with the 1st param being the last binding.

@Boshen
Copy link
Member

Boshen commented Jul 12, 2024

let semantic_ret = SemanticBuilder::new("", program.source_type).build(program);

Symbols and scopes are recreated, since mangler is the last stage just before codegen of the pipeline, even after the compressor.

@overlookmotel
Copy link
Member

I assume (perhaps incorrectly?) that our intention is that ultimately transform and compress will update symbols and scopes as they modify the AST, so we won't need to keep recreating them. So at that point, the binding insertion order / position mismatch could become a problem.

But perhaps we should leave this as is for now.

@Dunqing
Copy link
Member Author

Dunqing commented Jul 19, 2024

Close this because we're not sure yet that we can safely replace it with a FxHashMap.

@Dunqing Dunqing closed this Jul 19, 2024
@Boshen Boshen deleted the 07-12-perf_semantic_use_fxhashmap_instead_of_indexmap branch September 11, 2024 12:21
Boshen added a commit that referenced this pull request Dec 19, 2024
`IndexMap` was needed for the insertion order requirement in mangler.

Bindings (symbol ids) are monotonically increasing by binding
positions, which means get insertion order by sorting the symbol ids in
mangler.

Previous attempt: #4228
Boshen added a commit that referenced this pull request Dec 19, 2024
`IndexMap` was needed for the insertion order requirement in mangler.

Bindings (symbol ids) are monotonically increasing by binding
positions, which means we can get insertion order by sorting the symbol ids in
mangler.

Previous attempt: #4228
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants