Performance: Remove unnecessary dereferencing from YulString storage#16763
Open
DanielVF wants to merge 1 commit into
Open
Performance: Remove unnecessary dereferencing from YulString storage#16763DanielVF wants to merge 1 commit into
DanielVF wants to merge 1 commit into
Conversation
Member
|
Memory consumption is interesting here. Without having looked too closely at it, I think the shared pointers were deliberate to guard against (re)allocations. Perhaps interesting in this context though: #15969 |
Contributor
Author
|
Thanks for the link to the other PR. I do think it's a lot of unnecessary work to pre-create string labels for everything - would be great to see it removed. |
Contributor
Author
|
If the other PR is planned for inclusion in the next release, we could close this PR. Otherwise, we could roll this PR in now since it is a minimal change with no effects but performance, and hopefully get the big PR in the release after. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
~3% speed up to Yul compilation times with a small change.
Benchmark
Details
Yul compilation creates many YulString/YulName objects, most of these auto generated names. Compiling the AaveV4HubInstance contract creates around 100,000 of these instances. The current implementation around these strings is unnecessarily slow because there is an extra layer of indirection.
A core requirement for YulString.h is that the underlying string storage never changes a string's memory location and thus the underlying string can be safely pointed to from other places in the code. A shared pointer is used in the current code because when a vector resizes it may move where its immediate children are stored in memory. The shared pointer means these resizes never affect underlying string storage.
However, by switching the vector to an indexedable data structure that does not move the underlying memory when expanding (deque), the overhead of the intermediate shared pointer can be skipped and short strings can be stored directly into the container, without even a pointer to the heap. This has a major effect on the speed of working with strings in the compiler, since this speeds up creation, id based lookups, and string based lookups (as those also go through id based lookups).
This PR changes the type from
std::vector<std::shared_ptr<std::string>>tostd::deque<std::string>and then removes the now unnecessary pointer dereferencing from where the strings are looked up.Checklist
AI Disclosure
Codex 5.5