-
Notifications
You must be signed in to change notification settings - Fork 415
Optimize chunkOnModifiedUtf8ByteSize from O(n²) to O(n) #386
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
Merged
rossbacher
merged 2 commits into
airbnb:master
from
Nepomuk5665:fix/optimize-chunk-utf8-byte-size
Jan 23, 2026
Merged
Optimize chunkOnModifiedUtf8ByteSize from O(n²) to O(n) #386
rossbacher
merged 2 commits into
airbnb:master
from
Nepomuk5665:fix/optimize-chunk-utf8-byte-size
Jan 23, 2026
Conversation
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
The previous implementation created a new substring and converted it to a byte array for every character in the input string, resulting in O(n²) time complexity. This caused significant build time overhead as reported in airbnb#350. This fix calculates character byte sizes incrementally using the Modified UTF-8 encoding rules directly, reducing time complexity to O(n). The new modifiedUtf8ByteSize() helper function handles: - U+0000 (null): 2 bytes (C0 80 encoding) - U+0001-U+007F: 1 byte - U+0080-U+07FF: 2 bytes - U+0800-U+FFFF: 3 bytes All existing tests pass, confirming behavioral correctness.
Collaborator
|
This is great! thank you very much! Can you fix the Ci issues? Just run |
rossbacher
approved these changes
Jan 23, 2026
Collaborator
rossbacher
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Great fix!
This was referenced Jan 23, 2026
renovate bot
added a commit
to keelim/all
that referenced
this pull request
Jan 29, 2026
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [com.airbnb:deeplinkdispatch-processor](https://redirect.github.com/airbnb/deeplinkdispatch) | `7.2.1` → `7.2.2` |  |  | | [com.airbnb:deeplinkdispatch](https://redirect.github.com/airbnb/deeplinkdispatch) | `7.2.1` → `7.2.2` |  |  | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>airbnb/deeplinkdispatch (com.airbnb:deeplinkdispatch-processor)</summary> ### [`v7.2.2`](https://redirect.github.com/airbnb/DeepLinkDispatch/releases/tag/7.2.2): DeepLinkDispatch v7.2.2 [Compare Source](https://redirect.github.com/airbnb/deeplinkdispatch/compare/7.2.1...7.2.2) ##### What's Changed - Update AGP to 8.13.2 by [@​rossbacher](https://redirect.github.com/rossbacher) in [airbnb/DeepLinkDispatch#385](https://redirect.github.com/airbnb/DeepLinkDispatch/pull/385) - Optimize chunkOnModifiedUtf8ByteSize from O(n²) to O(n) by [@​Nepomuk5665](https://redirect.github.com/Nepomuk5665) in [airbnb/DeepLinkDispatch#386](https://redirect.github.com/airbnb/DeepLinkDispatch/pull/386) - Upgrade GitHub Actions for Node 24 compatibility by [@​salmanmkc](https://redirect.github.com/salmanmkc) in [airbnb/DeepLinkDispatch#390](https://redirect.github.com/airbnb/DeepLinkDispatch/pull/390) - Centralize toolchain and target compatibility version. by [@​rossbacher](https://redirect.github.com/rossbacher) in [airbnb/DeepLinkDispatch#388](https://redirect.github.com/airbnb/DeepLinkDispatch/pull/388) - Fix chunking algo for surrogate pairs by [@​rossbacher](https://redirect.github.com/rossbacher) in [airbnb/DeepLinkDispatch#389](https://redirect.github.com/airbnb/DeepLinkDispatch/pull/389) ##### New Contributors - [@​Nepomuk5665](https://redirect.github.com/Nepomuk5665) made their first contribution in [airbnb/DeepLinkDispatch#386](https://redirect.github.com/airbnb/DeepLinkDispatch/pull/386) - [@​salmanmkc](https://redirect.github.com/salmanmkc) made their first contribution in [airbnb/DeepLinkDispatch#390](https://redirect.github.com/airbnb/DeepLinkDispatch/pull/390) **Full Changelog**: <airbnb/DeepLinkDispatch@7.2.1...7.2.2> </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/keelim/all). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi45Mi4xIiwidXBkYXRlZEluVmVyIjoiNDIuOTIuMSIsInRhcmdldEJyYW5jaCI6ImRldmVsb3AiLCJsYWJlbHMiOlsiVVBEQVRFLW1pbm9yLXBhdGNoIl19-->
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
chunkOnModifiedUtf8ByteSizethat caused significant build time overheadBackground
This addresses the performance issue reported in #350. The original implementation created a new substring and converted it to a byte array for every character in the input string:
This is now replaced with an O(n) approach that calculates byte sizes incrementally:
Technical Details
The new
modifiedUtf8ByteSize()helper function handles Modified UTF-8 encoding rules:Testing
All existing tests in
CharSequenceUtf8Testpass, confirming behavioral correctness.