-
-
Notifications
You must be signed in to change notification settings - Fork 11
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 support for building optimized string table #30
Conversation
Thanks! Results look great, definitely agree that the current implementation of Will have a look at the PR later tonight. |
Looks like the CI was stuck because it was requesting I have switched to Also, when running locally, I got multiple errors from the DwarfTests, and they seem to be related to the string table changes. For example:
|
That particular error is fixed with #27. I also had trouble running the tests locally for the reasons you mentioned. |
Oh, good catch, just merged! I'm starting to ask myself If I should not make this library only compatible with net7.0. Would it be a problem for your experiment? |
Not at all. I am fine with that. I think I publish my Mach-O libraries as net6.0+ since that's still supported LTS release but I don't mind a higher version either. |
Ok, just bumped on master to net7.0.
Might ignore it for a time and add an issue. Don't have time to investigate this one and it might take some time to upgrade. |
I may get to look into it, but this week is exceptionally busy, so I cannot promise any timeline. |
The current implementation of
ElfStringTable
doesn't scale well in terms of time and memory usage. This was discovered in the experiment which uses LibObjectFile as ELF emitting backend for the .NET NativeAOT. Link to the discussion thread.The root cause of the issue is the optimization that tries to deduplicate strings that share the same suffix. This optimization creates enormous amount of strings on the managed heap, creates a dictionary with large amount of collisions, and produces only marginally better output for the common cases. It doesn't produce the optimal solution either since it depends on the order of the strings.
I created a benchmark to see how bad the problem is and what can be done to improve the situation. The benchmark implements two strategies (
MultiKeySort
andNaive
) in addition to the currentElfStringTable
implementation used for reference. TheMultiKeySort
algorithm produces the optimal solution by pre-sorting the input, theNaive
algorithm does no suffix deduplication.Results on my Ryzen 7950X machine:
The
MultiKeySort
algorithm produces an output that is 23% smaller than theNaive
implementation for the sample data. Notably,MultiKeySort
is more than 50 times faster than the current implementation and uses 65 times less memory in the process.ElfStringTable
offers an API that can build the string table incrementally, but the most common case is when it's populated from the symbol table. I present a solution where the symbol table case uses theMultiKeySort
algorithm by introducing a newElfStringTable.ReserveString
method and then builds the optimal solution lazily when the string table is emitted or indexed. The existingGetOrCreateIndex
method is modified to use the naive implementation and removes the suffix optimization.