String.split/1 refactor - #15781
Closed
dkuku wants to merge 1 commit into
Closed
Conversation
Member
|
I pushed some PRs to OTP that make binary:split much faster because it uses SIMD, so I would like to see where those land first: erlang/otp#11467 Thank you! |
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.
Currently
String.split/1is using:binary.split(string, unquote(whitespace -- non_breakable), [:global, :trim_all]), which is only beneficial on long inputs like files 100kB+ — where you probably want to tweak your split chars anyway.This pays a pattern-compilation cost on every call: the needle list is passed as a literal, so the automaton for the whitespace codepoints is rebuilt each time.
Refactor into multiple function heads — just like the other functions in this module.
I compared on a full file input (145K) where speed is comparable, the same file split by lines, and 2 word pairs.
The other 2 benchmarks are comparing splitting lines and 2 word pairs.
I know that comparing this in an Enum loop may show the existing implementation much slower but I think it is the most common pattern.