Skip to content

Fast date/time parser - #310

Draft
vpaturet wants to merge 1 commit into
masterfrom
perf/fast-local-date-time-parser
Draft

vpaturet wants to merge 1 commit into
masterfrom
perf/fast-local-date-time-parser

Conversation

@vpaturet

@vpaturet vpaturet commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Parsing xs:time, xs:date and xs:dateTime values with a DateTimeFormatter is CPU and memory intensive.

This PR adds FastLocalDateTimeParser, which reads fields at fixed positions. It follows the same approach as FastZonedDateTimeParser in siri-java-model. It supports:

type form
xs:date yyyy-MM-dd[Z|±HH:MM]
xs:time HH:mm:ss[.fffffffff][Z|±HH:MM]
xs:dateTime yyyy-MM-ddTHH:mm:ss[.fffffffff][Z|±HH:MM]

The zone designator is validated, then ignored, as the current formatters already do.

The three adapters try the fast parser first. For any other form, any out-of-range field or a null input, they fall back to their existing DateTimeFormatter. That keeps results, lenient resolution (2023-02-30 → 2023-02-28, 24:00:00, 10:20:30.) and exceptions unchanged, including the formatter's NullPointerException for null.

LocalTimeISO8601XmlAdapter keeps its ConcurrentHashMap deduplication of whole-second times, so retained heap is unchanged.

Results

Measured by unmarshalling the full Norwegian NeTEx export, compared with master:

master this PR
wall time 63.5–73.6 s 55.6–56.8 s
allocation 35.3 GB 23.2 GB (−34%)
date/time adapters 8.4 s / 12.3 GB 0.6 s / 0.38 GB

Tests

FastLocalDateTimeParserTest covers the supported forms, the inputs the fast parser declines and leaves to the formatter (day overflow, 24:00:00, a fraction separator without digits, malformed or out-of-range offsets, extra year digits, ...), and null handling in the parser and the three adapters.

@vpaturet
vpaturet force-pushed the perf/fast-local-date-time-parser branch from 4f64a46 to ab0d343 Compare October 7, 2026 08:07
@vpaturet vpaturet changed the title perf: parse common NeTEx date/time forms without DateTimeFormatter Fast date/time parser Oct 7, 2026
Parsing xs:time, xs:date and xs:dateTime values with a DateTimeFormatter
costs 500-900 ns and 1-1.7 KB of garbage per value, spent in the
formatter machinery to parse strings that in practice have one fixed
shape. NeTEx documents contain millions of such values (10.4M xs:time
values in the Norwegian aggregated dataset).

Add FastLocalDateTimeParser, a position-based parser for
yyyy-MM-dd, HH:mm:ss[.fffffffff] and yyyy-MM-ddTHH:mm:ss[.fffffffff],
each with an optional Z or ±HH:MM zone designator that is validated
and ignored, as the formatters do. The three adapters try it first and
fall back to their existing DateTimeFormatter for any other form or
out-of-range field, so results, lenient resolution (e.g. 2023-02-30,
24:00:00) and exceptions are unchanged. LocalTimeISO8601XmlAdapter
keeps its ConcurrentHashMap deduplication of whole-second times.

Same approach as FastZonedDateTimeParser in siri-java-model.
@vpaturet
vpaturet force-pushed the perf/fast-local-date-time-parser branch from c0d7c77 to 7be6066 Compare October 7, 2026 11:40
@sonarqubecloud

sonarqubecloud Bot commented Oct 7, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant