Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add hashmap to get_const_offset #4010

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sjamesr
Copy link
Contributor

@sjamesr sjamesr commented Jan 7, 2025

No description provided.

@sjamesr
Copy link
Contributor Author

sjamesr commented Jan 7, 2025

This change has worse performance than HEAD for small modules, but it is a substantial improvement for modules with large numbers of constants (I saw a 18% speedup in loading a module with 10,000 consts).

Ideas:

  • Right now there are at least 3 allocations per insertion. Right now the hashmap keys and const buffer memory cannot be shared, because the constant buffer will be realloc'd when it grows, potentially invalidating the pointers in the hashmap. Perhaps the constant buffer could be a linked list of chunks of N constants. This way, more constant buffer space could be added without reallocating the existing buffer.

  • hash map uses chaining to resolve collisions. Moving to open addressing would reduce the number of allocations.

  • maybe the loader should be smarter about using a hash map only when the number of constants grows beyond a certain threshold

  • maybe toolchains should emit table references instead of {i32,i64,f32,f64}.const instructions, thus moving the de-dup/compression step to the assembler/linker and out of the loader

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant