Skip to content

Optimize Schema metadata, and Row - #41746

Open
reuvenlax wants to merge 1 commit into
apache:masterfrom
reuvenlax:perf/schema-01-core-model
Open

reuvenlax wants to merge 1 commit into
apache:masterfrom
reuvenlax:perf/schema-01-core-model

Conversation

@reuvenlax

Copy link
Copy Markdown
Contributor

No description provided.

…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.
@github-actions github-actions Bot added java core size/xl XL: >=1000 lines changed labels Nov 29, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 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 existing Options instance in place.
  • Consider adding unit tests covering the newly fixed Row.Equals.deepHashCode behavior on logical types, RowWithGetters vs RowWithStorage hash code parity, and Schema.getContainerCacheSlot for schemas with >= 64 fields.

💡 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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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).

Suggested change
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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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).

@github-actions

Copy link
Copy Markdown
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

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

Labels

core java size/xl XL: >=1000 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant