Repository navigation
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR introduces well-targeted, low-risk performance optimizations to hot-path coders (BitConverters, InstantCoder, LengthPrefixCoder, IntervalWindow, and PaneInfo), alongside unit tests and JMH microbenchmarks. All wire formats and error semantics are preserved while eliminating unnecessary allocations (byte[], Duration, Instant, ByteArrayOutputStream, and PaneInfo instances).
🔍 General Feedback
- The
LengthPrefixCoderfast-path forByteArrayCoderandStringUtf8Codercleanly leverages their existingContext.NESTEDlength-prefixing behavior, and the boundedThreadLocalbuffer pool safely handles reentrancy and large payloads. - Arithmetic in
IntervalWindowandIntervalWindowCodermatches Joda-TimeFieldUtils.safeSubtractsemantics viaMath.subtractExactwithout intermediateDurationallocations.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
|
Optimization-by-Optimization Trade-Off Evaluation
Ran some microbenchmarks on my sides:
From the results it appears we should simply revert the BitConverters changes (and its tests). We may also want to consolidates/simplify test cases, avoid change-detection tests, as the main change looks thin while there are many unit tests testing line-by-line behaviors |
- BitConverters: eliminate per-call byte[] allocations on big/little-endian encode/decode. - InstantCoder: encode/decode directly with primitive shifts and return canonical BoundedWindow.TIMESTAMP_MIN_VALUE / TIMESTAMP_MAX_VALUE singletons. - LengthPrefixCoder: delegate ByteArrayCoder and StringUtf8Coder directly to NESTED context and pool reusable byte buffers for other inner coders. - IntervalWindow: encode/decode window duration directly via VarInt without allocating Duration objects and avoid Duration allocation in maxTimestamp(). - PaneInfo: return `this` in withElementMetadata when unchanged and avoid duplicate chooseEncoding() calls in PaneInfoCoder.encode(). - Add unit tests in LengthPrefixCoderTest and JMH microbenchmarks in CoreCodersBenchmark.
e96d29a to
7b9906f
Compare
|
I took another look, because I got better results than you on my benchmarking run (for BitConverters). However after looking, I think you were right - the error bars were large, and the results I got were within the noise. Rewrote the BitConverters change to avoid the use of the ThreadLocal, and results look much better. bigEndianLongEncode is now twice as fast, and instantEncode is nearly twice as fast. LengthPrefixCoder rewritten to use SoftReference, as suggested. Cleaned up test classes. |
thisin withElementMetadata when unchanged and avoid duplicate chooseEncoding() calls in PaneInfoCoder.encode().