Skip to content

Cache CAPIType values - #790

Merged
staticlibs merged 1 commit into
duckdb:mainfrom
kkristof93:cache-capitype-values
Aug 7, 2026
Merged

Cache CAPIType values#790
staticlibs merged 1 commit into
duckdb:mainfrom
kkristof93:cache-capitype-values

Conversation

@kkristof93

Copy link
Copy Markdown
Contributor

CAPIType.capiTypeFromTypeId() called CAPIType.values() on every invocation, which allocates a fresh array copy of all enum constants each time. For a hot path (type resolution on every vector/column read) this creates unnecessary heap allocations and linear scan overhead.

The fix introduces a BY_TYPE_ID static array built once during class initialization by iterating values() a single time. Lookups are now a bounds check plus a single array dereference (O(1) with no allocation, compared to the previous O(n) scan with a transient array allocation per call).

@staticlibs staticlibs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR! Looks good to me. I'll add it to 1.5 branch and will publish a snapshot shortly.

@staticlibs
staticlibs merged commit f8e5cc4 into duckdb:main Aug 7, 2026
29 of 30 checks passed
staticlibs pushed a commit that referenced this pull request Aug 7, 2026
This is a backport of the PR #790 to `v1.5-variegata` stable branch.
@staticlibs

Copy link
Copy Markdown
Member

Snapshot with this change was published, compatible with DuckDB 1.5.5:

<dependency>
    <groupId>org.duckdb</groupId>
    <artifactId>duckdb_jdbc</artifactId>
    <version>1.5.5.2-dev-651bc51</version>
</dependency>
<repository>
    <id>duckdb</id>
    <url>https://duckdb-staging.duckdb.org/duckdb/duckdb-java/maven/</url>
</repository>

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.

2 participants