Skip to content

GH-3507: Reduce allocation overhead of no-op GeospatialStatistics.Builder#3508

Open
arouel wants to merge 1 commit intoapache:masterfrom
arouel:geospatial-singleton-no-op-builder
Open

GH-3507: Reduce allocation overhead of no-op GeospatialStatistics.Builder#3508
arouel wants to merge 1 commit intoapache:masterfrom
arouel:geospatial-singleton-no-op-builder

Conversation

@arouel
Copy link
Copy Markdown

@arouel arouel commented Apr 19, 2026

Rationale for this change

GeospatialStatistics.noopBuilder() is called for every non-geometry column in every row group. Each call allocates a new NoopBuilder along with a WKBReader, BoundingBox, and GeospatialTypes that are never used. Each subsequent build() allocates a new GeospatialStatistics(null, null) that is equally throwaway. On wide schemas with many columns, this creates unnecessary GC pressure on the write path.

What changes are included in this PR?

  • Make NoopBuilder a singleton via a static INSTANCE field returned by noopBuilder()
  • Cache the build() result as a static EMPTY instance, since it is stateless (null fields, with merge/abort guarded by null checks)
  • Add a package-private Builder(boolean) constructor that skips field initialization so the singleton does not allocate unused WKBReader, BoundingBox, and GeospatialTypes objects
  • Move WKBReader initialization from the field declaration into the public Builder() constructor, so only real builders pay the cost

Are these changes tested?

Yes. Two new tests were added to TestGeospatialStatistics:

  • testNoopBuilderIsSingleton: verifies noopBuilder() returns the same builder instance and build() returns the same cached result
  • testNoopBuilderUpdateAndAbortAreNoOps: exercises update(nonNull), update(null), and abort() on the noop builder to confirm none throw, and asserts the built result remains invalid with null fields

Are there any user-facing changes?

No. This is an internal optimization with no API or behavioral changes.

Closes #3507

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reduce allocation overhead of no-op GeospatialStatistics.Builder

1 participant