Skip repetetive LocalDate parsing - #300
Open
leonardehrenfried wants to merge 1 commit into
Open
leonardehrenfried wants to merge 1 commit into
leonardehrenfried wants to merge 1 commit into
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
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
LocalTimeISO8601XmlAdapter.unmarshalwas showing up in real-world profiling as a hotspot: NeTEx documents contain a very large number ofLocalTimevalues, and every one of them was going throughDateTimeFormatter.parse, which is comparatively expensive.Since a day only has 86,400 distinct whole-second times, this PR precomputes all of them once at class-load time:
TIMES_BY_SECOND_OF_DAY— aLocalTime[86400]array indexed by second-of-day, used to hand back a canonical, deduplicated instance.TIME_BY_STRING— aMap<String, LocalTime>from the formatted"HH:mm:ss"string to that same canonical instance.Flame graph
Before
After
Real-world improvement
When using this improvement in an OTP graph build with a very large (50GB!) NeTEx feed this leads to some very noticeable graph build improvements.
Before
After
So 90 seconds was spent in repeatedly parsing LocalTimes!
Memory tradeoff
The previous cache was a
ConcurrentHashMappopulated lazily — it only held entries for times actually seen, so a typical document with a handful of distinct times cost next to nothing.The new cache is precomputed unconditionally at class-load time, so it always costs the same, whether or not the times are ever used.
Measured via heap-delta on class load:
DateTimeFormatterclass loading)Net additional cost: ~11-12 MB, permanent for the life of the JVM. This is a fixed one-time cost, not per-instance, and trivial relative to typical heap sizes — but worth calling out since it's paid upfront rather than proportionally to usage.
cc @flaktack
Ref: noi-techpark/opendatahub-mentor-otp#330