Skip to content

perf(wamrc): Replace slow symbol lookup with hash map in wamrc#4912

Open
jammar1 wants to merge 1 commit intobytecodealliance:mainfrom
jammar1:mrshnja/wamrc-faster-symbol-lookup
Open

perf(wamrc): Replace slow symbol lookup with hash map in wamrc#4912
jammar1 wants to merge 1 commit intobytecodealliance:mainfrom
jammar1:mrshnja/wamrc-faster-symbol-lookup

Conversation

@jammar1
Copy link
Copy Markdown
Contributor

@jammar1 jammar1 commented Apr 13, 2026

Replace slow symbol lookup with hash map in AOT compilation.

The relocation symbol deduplication in aot_emit_aot_file.c used a linked list, requiring O(n) traversal per relocation to check for duplicates.

Replace with a lazily-allocated hash map for O(1) lookups. The linked list is preserved for ordered iteration during emission.

When testing against a fairly large Wasm binary (about 18MB) this reduced compilation time by about ~15%.

…ion/emission

The relocation symbol deduplication in aot_emit_aot_file.c used a linked
list, requiring O(n) traversal per relocation to check for duplicates.

Replace with a lazily-allocated hash map for O(1) lookups.
The linked list is preserved for ordered iteration during emission.
Copy link
Copy Markdown
Contributor

@lum1n0us lum1n0us left a comment

Choose a reason for hiding this comment

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

Thanks for the optimization! The performance improvement is meaningful.

However, I have a question about the design: currently, when a new symbol is not found, the code creates both an AOTSymbolNode (for the linked list) and an AOTSymbolHashEntry (for the hash table). This means two separate allocations storing the same symbol and index.

Is there a specific reason to keep the linked list if the hash table already provides O(1) lookup? The linked list seems to only be used for ordered iteration during destruction, which could also be done by iterating the hash table buckets?

@jammar1
Copy link
Copy Markdown
Contributor Author

jammar1 commented Apr 16, 2026

We do currently use the list for symbol emission too, in aot_emit_relocation_symbol_table. The hash entry is just storing a pointer to the string so it doesn't use much extra memory. We could completely swap to just using a hash map if we also added str_len to it as long as the iteration order is consistent between the passes. Happy to do either.

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.

2 participants