ORC, Flink: Avoid redundant java.time allocations when reading ORC timestamps - #16731
Open
wombatu-kun wants to merge 1 commit into
Open
ORC, Flink: Avoid redundant java.time allocations when reading ORC timestamps#16731wombatu-kun wants to merge 1 commit into
wombatu-kun wants to merge 1 commit into
Conversation
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions. |
Contributor
Author
|
no stale |
…mestamps Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
wombatu-kun
force-pushed
the
orc-timestamp-reader-alloc
branch
from
August 4, 2026 02:42
8d1b21b to
c18482a
Compare
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.
The generic and Flink ORC timestamp value readers build throwaway
java.timeobjects on every value. Reading atimestamp/timestamptzcolumn went throughInstant.ofEpochSecond(...).atOffset(ZoneOffset.UTC)[...], which allocates, per value: a transientInstant; anOffsetDateTimethat is immediately discarded (for the readers that ultimately return aLocalDateTime/TimestampData); and, less obviously, aZoneRulesobject plus a small backing array, becauseinstant.atOffset(ZoneOffset.UTC)routes throughOffsetDateTime.ofInstant(instant, zone), which callszone.getRules(), andZoneOffset.getRules()returns a freshly allocatedZoneRuleson every call.This replaces those expressions with direct constructions that pass the
ZoneOffsetstraight to the factory methods and never callgetRules(). For example, inGenericOrcReaders:The
timestamptzreaders follow the same shape (OffsetDateTime.of(LocalDateTime.ofEpochSecond(...), UTC)in the generic reader;TimestampData.fromInstant(Instant.ofEpochSecond(...))in Flink). The FlinkTimestampTzReaderadditionally didInstant.ofEpochSecond(...).atOffset(UTC).toInstant(), an identity round-trip back to anInstant, which is now removed.All rewrites are behavior-preserving.
instant.atOffset(UTC).toLocalDateTime()is exactly whatLocalDateTime.ofEpochSecond(seconds, nanoOfSecond, UTC)produces, and the readers always passtcv.nanos[row], which is in[0, 1_000_000_000)(it carriesjava.sql.Timestamp.getNanos()semantics; the whole second and the sign live intcv.timeand are split out withMath.floorDiv), so thenanoOfSecondrange contract ofLocalDateTime.ofEpochSecondis always satisfied.Affected readers:
GenericOrcReaders(TimestampReader,TimestampTzReader) - the genericRecordORC path, used byIcebergGenericsand by delete-file reads viaBaseDeleteLoader.FlinkOrcReadersfor v2.1 (TimestampReader,TimestampTzReader) - the Flink ORC scan path. The change is identical for v1.20 and v2.0; a backport PR will follow.Benchmarks (JMH, JDK 17,
SingleShotTime,gcprofiler; allocation isgc.alloc.rate.norm, which is deterministic):Generic
Recordread, 2.5M rows x 8 timestamp columns (20M values/op):Flink
TimestampDatareaders, 10.24M values/op:After the change both Flink readers bottom out at the 24-byte
TimestampDataresult, because simplifying the expression also lets the JIT scalar-replace the residualLocalDateTime/LocalDate/LocalTime(in the original, theatOffsetdetour and the escapingZoneRulesdefeated escape analysis).Testing: covered by existing round-trip tests -
TestGenericData(parameterized overtimestamp,timestamptz,timestamp_ns,timestamptz_ns, including negative epochs and a cross-timezone write/read) andTestFlinkOrcReaderWriter; both pass with the change.AI Disclosure