Optimize StringIntegerMap construction: counting sort + skip debug-only duplicate checks#172
Merged
meta-codesync[bot] merged 1 commit intometa-pytorch:mainfrom Feb 12, 2026
Conversation
|
@redmercury has exported this pull request. If you are a Meta employee, you can view the originating Diff in D92973393. |
larryliu0820
approved these changes
Feb 11, 2026
Contributor
larryliu0820
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
af24532 to
6a70413
Compare
…ly duplicate checks (meta-pytorch#172) Summary: Replace O(n log n) std::sort with O(n) counting sort for bucket distribution, skip duplicate-detection sorts in release builds, and replace unordered_map cross-reference with direct index array. Simpleperf profiling of assistant startup on Supernova (hammerhead) showed tokenizers::Tiktoken::load() consuming 14% of all CPU cycles, dominated by StringIntegerMap construction sorting and hashing ~200K token entries. Construction benchmark (opt build, x86_64): - Baseline: 81.3 ms -> Optimized: 25.2 ms (3.2x faster) On-device boot metrics (50 runs each, Supernova/hammerhead): - Mean assistant ready time: 15.625s -> 15.341s (-285ms) - P50 assistant ready time: 15.810s -> 15.369s (-441ms) - Welch t-test: t=-2.587, p<0.05, 95% CI [-500, -69]ms - Boots completing under 15s: 20% -> 48% Reviewed By: larryliu0820 Differential Revision: D92973393
6a70413 to
655d6e9
Compare
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.
Summary:
Replace O(n log n) std::sort with O(n) counting sort for bucket distribution,
skip duplicate-detection sorts in release builds, and replace unordered_map
cross-reference with direct index array.
Simpleperf profiling of assistant startup on Supernova (hammerhead) showed
tokenizers::Tiktoken::load() consuming 14% of all CPU cycles, dominated by
StringIntegerMap construction sorting and hashing ~200K token entries.
Construction benchmark (opt build, x86_64):
On-device boot metrics (50 runs each, Supernova/hammerhead):
Reviewed By: larryliu0820
Differential Revision: D92973393