Repository navigation
Conversation
…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.
There was a problem hiding this comment.
📋 Review Summary
This PR introduces well-targeted performance optimizations across Schema, Row, RowWithStorage, RowWithGetters, FieldAccessDescriptor, RowMessages, and SchemaUtils to eliminate steady-state allocations and hash lookups. It also fixes two important correctness bugs: Row.Equals.deepHashCode now converts logical types to their base type before hashing, and RowWithGetters.hashCode() now delegates to super.hashCode() to maintain the equals/hashCode contract when comparing against RowWithStorage.
🔍 General Feedback
- There is a shallow-copy mutability bug in
Schema.Options.toBuilder()that allows mutating an existingOptionsinstance in place. - Consider adding unit tests covering the newly fixed
Row.Equals.deepHashCodebehavior on logical types,RowWithGettersvsRowWithStoragehash code parity, andSchema.getContainerCacheSlotfor schemas with>= 64fields.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
|
||
| Options.Builder toBuilder() { | ||
| return new Builder(new HashMap<>(this.options)); | ||
| return this.options.isEmpty() ? new Builder() : new Builder(this.options); |
There was a problem hiding this comment.
🔴 Critical: new Builder(this.options) stores the passed map reference directly without copying (this.options = options; at line 1598). When this.options is non-empty, calling toBuilder().setOption(...) will directly mutate the backing HashMap of the existing Options instance, violating Schema immutability. toBuilder() must pass a defensive copy new HashMap<>(this.options).
| return this.options.isEmpty() ? new Builder() : new Builder(this.options); | |
| return this.options.isEmpty() ? new Builder() : new Builder(new HashMap<>(this.options)); |
| int cacheSlot = schema.getContainerCacheSlot(fieldIdx); | ||
| if (cacheSlot >= 0) { | ||
| AtomicReferenceArray<@Nullable Object> localCache = cache; | ||
| if (localCache == null) { |
There was a problem hiding this comment.
🟡 Medium: If RowWithGetters is accessed concurrently by multiple readers (as noted in the comment on line 45), lazy initialization of cache without compareAndSet can cause a benign race where one thread's newly allocated AtomicReferenceArray overwrites another's, causing a cached container getter to be invoked more than once. If single-evaluation or strict reference identity of cached containers across threads is desired, consider using an AtomicReferenceFieldUpdater (or initializing cache in the constructor when schema.getCacheableContainerCount() > 0).
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
No description provided.