-
Notifications
You must be signed in to change notification settings - Fork 7
Hand rolled parser for SlsVersionType.RELEASE (aka x.y.z) #463
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
Conversation
dfa2b1a to
ef64650
Compare
Generate changelog in
|
| * We bit-pack these two integer values into a single long using {@link Parsers#ok} and {@link Parsers#fail} functions | ||
| * because primitive longs live on the stack and don't impact GC. | ||
| */ | ||
| final class Parsers { |
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.
all these functions just got moved from SlsVersionMatcherParser.java - no changes made here.
10c936f to
9d24113
Compare
sls-versions/src/main/java/com/palantir/sls/versions/Parsers.java
Outdated
Show resolved
Hide resolved
| state = Parsers.literalDot(string, Parsers.getIndex(state)); | ||
| if (Parsers.failed(state)) { | ||
| return null; | ||
| } |
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.
This is just begging for some kind of monadic bind abstraction... but obviously that would require a lot of allocation in Java.
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.
totally agree
| if (Parsers.failed(state)) { | ||
| return null; | ||
| } | ||
| int third = Parsers.getResult(state); |
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.
I was thinking maybe you could make this less duplicated by having a for loop - but then you'd need to either make an an array or have Int3MatchResult be mutable/have a builder.
You could also group literalDot/number into a method, but it would need to return Integer so it can be nullable, which would I guess would be bad.
|
👍 |
|
Released 0.18.0 |
Before this PR: 416 bytes / op
From 1 minute JFR, the hottest method in my application is currently
java.util.regex, and the biggest proportion of these Matcher constructions are coming from the lovelyOrderableSlsVersion#safeValueOfThis seems a bit silly, given that most of the time we're trying to parse three numbers with dots in between them.
After this PR: 104 bytes / op
==COMMIT_MSG==
Deserializing a verison of the form
x.y.znow allocates less. This should mean GC algorithms have less work to do.==COMMIT_MSG==
Possible downsides?