Repository navigation
Optimize Beam schemas - #41699
Optimize Beam schemas#41699reuvenlax wants to merge 15 commits into
Conversation
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
…wMessages Eliminates steady-state allocations and hash lookups across core schema model types: - Schema: singleton Options.none(), switch-based TypeName predicates, O(1) nameOf/getFieldNames, fast equals/equivalent, and safely published SchemaMetadata bitmasks with POPCNT (<64) and lazy highContainerCacheSlots (>=64) compact container slot lookup. - Row / RowWithStorage: internal zero-copy Row.attachValues(Schema, Object[]) and Row.withFieldValueGetters factories, direct Object[] backing in RowWithStorage, single-alloc getDateTime, fast getBaseValues, and reference-identity deepEquals / logical-type deepHashCode fix. - RowWithGetters: compact lazy container cache array replacing TreeMap + per-call anonymous Function, pre-resolved getter constructor, and hashCode parity with RowWithStorage. - FieldAccessDescriptor / RowMessages / SchemaUtils: cached singleton descriptors, fast schema-identity check and pre-sized buffers in RowToBytesFn, and shared path/identity helpers.
57548e9 to
3ac3274
Compare
…okup caches Replaces Row.Builder allocations with zero-copy Row.attachValues, adds transient lookup/value caches on EnumerationType and OneOfType, replaces Math.pow with precomputed scaling tables in Timestamp, and removes redundant boxing across DateTime, FixedPrecisionNumeric, MicrosInstant, NanosInstant, NanosDuration, NanosType, and UuidLogicalType.
Eliminates reflection, redundant container copies, double getter evaluation, and LogicalType triple round-trips in ByteBuddy codegen and schema providers: - ByteBuddyUtils: elides identity container/map Function wrappers and TransformingMap copies, caches singleton Function instances and Enum.values(), spills IfNullElse values to avoid double getter evaluation, uses ClassValue-anchored caches, and fast-paths primitive arrays. - JavaBeanUtils / SetterBasedCreatorFactory / JavaBeanSchema: adds cached ByteBuddy setter-based JavaBean creator (falling back safely to reflection with hoisted Constructor/FieldValueSetter[]). - POJOUtils: chunks >128-field POJO creators into 64-field setChunk helpers with generation-time zero-arg constructor validation. - GetterBasedSchemaProvider / FromRowUsingCreator / CachingFactory: eliminates LogicalType toBaseType/toInputType round-trips, avoids per-row CHM/Optional/identity-converter overhead, and adds monomorphic CachingFactory fast slot. - AutoValueUtils / ConvertHelpers / ReflectUtils: adds ClassValue-anchored codegen caches and reuses DefaultTypeConversionsFactory.INSTANCE.
… codecs and lazy byte-size observation Eliminates per-row allocation, megamorphic coder dispatch, and full re-encoding during byte-size observation while preserving 100% beam:coder:row:v1 wire compatibility: - RowWireCodec: shared buffered single-flush wire engine using re-entrancy-safe ScratchPool (MAX_DEPTH=8) and GC-safe RefScratchPool, byte-array VarHandles (SHORT_BE/INT_BE/INT_LE/LONG_BE), unrolled VarInt/5-byte VarLong readers, single-pass 8-fields/byte wide null bitmaps, and direct wire/size codecs for 29 field kinds. - RowCoderGenerator: monomorphic GeneratedRowCoder with 1..64 unrolled and 65..1024 32-field chunked RowFieldCodec (unlocked generation, weighted Metaspace cap of 512, omitted dead chunk families, direct mask==0 dispatch, needsDecodeScratch skip), >1024 zero-alloc wide-bitmap loop fallback, and O(1)/lazy ElementByteSizeObservableIterable byte-size observation. - SchemaCoderHelpers / SchemaCoder / RowCoder: direct wire/size LogicalTypeCoders, PassThroughLogicalType unwrapping, volatile delegateCoder, and byte-size observer delegation.
Generates fused ByteBuddy Coder<T> implementations for accessible POJO and JavaBean types that read/write unboxed fields, getters, and setters directly against RowWireCodec without RowWithGetters, RowWithStorage, Object[], or FromRowUsingCreator overhead: - Supports 1..64-field single-method unrolled codecs and 65..512-field 32-field chunked codecs (with single-buffer in-place wide null header packing, evaluate-once RefScratchPool for wide nullable JavaBeans, bit-packed zero-alloc chunked byte-size observation, OOM-safe try/catch pool scopes, and automatic schema-evolution fallback). - Wires direct-coder dispatch into SchemaCoder (falling back transparently for >512 fields or inaccessible/unsupported types). - Adds comprehensive DirectSchemaCoderTest covering unrolled and chunked POJO/JavaBean/RowCoder paths, exact cutoffs (64/65/1024/1025/4200), reversed encodingPositions, evolution, error branches, RowWireCodec edge cases, POJOUtils chunked creators, and Schema compact caching.
Eliminates unnecessary POJO-to-Row round-trips, per-element schema inspection, and intermediate row copies across core field-level schema transforms: - Filter: operates directly on typed @element T / OutputReceiver<T> with direct single-field path reads instead of round-tripping POJOs through Row. - Cast: precomputes CastPlan with identity-schema pass-through and zero-copy Row.attachValues output. - RenameFields: precomputes RenamePlan (fixing depth >= 2 rename bugs and avoiding RowWithGetters.getValues() raw-getter hazard). - AddFields / DropFields / Convert: uses direct array access, identity function checks, and Row.attachValues.
Eliminates eager full-row cloning on wildcard field access and bounds selector codegen caching: - SelectByteBuddyHelpers: short-circuits wildcard getAllFields() to return input directly, parameterizes outputSchema (fixing uniquifyNames leaks and UUID mismatches), hoists checkcasts, optimizes list/map selection, and bounds the generated selector cache at 512 entries. - SelectHelpers / Select / WithKeys: adds output-schema-aware RowSelectorContainer constructor, caches RowSelector transiently on DoFns, and shares rewrapRow/countRowFields helpers.
Fixes major aggregation allocation and combiner-lifting bugs: - SchemaAggregateFn: fixes needsFlattening check (comparing inputSubSchema instead of inputSchema), extracts single-field inputs directly without allocating throwaway Rows, adds compact(Object[]) override, and uses Row.attachValues for outputs. - Group: preserves fewKeys=true in withHotKeyFanout so streaming combiner lifting remains enabled. - CombineFns: eliminates eager string concatenation and unnecessary allocations in CoCombineResult and mergeAccumulators.
…st path, and fused broadcast joins Replaces per-key AutoValue/Map/TupleTag wrapper overhead with flat arrays, short-circuits inner joins when any required side is empty, adds a specialized 2-way join fast path, uses output-schema-aware RowSelectorContainer, and fuses broadcast join key extraction.
… timer maps Shares Row conversion across multi-parameter @FieldAccess DoFn invocations, reads single-field paths directly via SchemaUtils.readFieldPath, and initializes DoFnInvokerBase timer maps lazily.
Reduces per-record JSON and YAML Java provider allocations and recompilation overhead: - JsonUtils / RowJsonUtils: reuses ObjectReader/ObjectWriter and adds direct UTF-8 byte[] serialization/deserialization without intermediate Strings. - JavaExplode / JavaFilter / JavaMapToFields / JavaRowUdf / StringCompiler / LoggingTransformProvider: caches compiled UDF classes, skips guessExpressionType on reload, uses indexed array/Row.attachValues access, and adds SLF4J level guards.
Eliminates eager String.format allocations in checkRawType, caches toAvroSchema conversions, shares a static DecimalConversion instance, avoids stream/filter allocations on nullable unions, and fast-paths numeric/timestamp conversions.
Caches volatile Protobuf parsers and uses getSerializedSize() in ProtoCoder/DynamicProtoCoder, caches descriptors and OneOf/builder creators in ProtoByteUtils/ProtoByteBuddyUtils, fast-paths matching schemas in ProtoPayloadSerializerProvider, and uses Row.attachValues in ProtoSchemaLogicalTypes.
Caches field accessors and serializable creators in ThriftSchema, optimizes AwsSchemaProvider getter/creator lookups, and uses zero-copy Row.withFieldValueGetters in ArrowConversion.
Adds 58 JMH microbenchmarks (plus JUnit smoke test) covering Schema/Row operations, built-in LogicalTypes, RowCoder/SchemaCoder encode/decode/byte-size (flat, nullable, nested, wide, POJO, JavaBean, lazy iterables), and core schema transforms (Select, Cast, SchemaAggregateFn).
3ac3274 to
441fc9f
Compare
|
Assigning reviewers: R: @chamikaramj for label java. This pull request likely touches a core component ("core" label). Please review with scrutiny. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #41699 +/- ##
=========================================
Coverage 59.54% 59.54%
Complexity 5156 5156
=========================================
Files 1470 1470
Lines 187776 187776
Branches 3828 3828
=========================================
Hits 111820 111820
Misses 72549 72549
Partials 3407 3407 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
No description provided.