Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary & Bottleneck
When callers access row values by column name via
FieldValueList.get(String name), every cell lookup delegates toFieldList.getIndex(String name). Previously,FieldListbackednameIndexwith a customCaseInsensitiveMapsubclass ofHashMapthat executedkey.toString().toLowerCase()on everyget(Object key)call.CamelCaseorUPPER_SNAKE_CASE),String.toLowerCase()allocated a newStringand backing byte array on every cell read across every row (String.toLowerCase()scanned every character of the column name on every cell access and consultedLocale.getDefault().new CaseInsensitiveMap()initialized the underlyingHashMapwith default capacity (16), causing repeated table resizing on wide schemas.Changes
java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FieldList.java:nameIndexusingMaps.newHashMapWithExpectedSize(size * 2)and populate both the lowercase column name (name.toLowerCase(Locale.ROOT)) and the exact-case column name atFieldListconstruction time.getIndex(String name), probenameIndex.get(name)first so exact-case and lowercase column names resolve in a single hash probe with zero character scanning and zero allocations, falling back tonameIndex.get(name.toLowerCase(Locale.ROOT))only on a miss.java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/FieldListTest.java:testGetIndexExactLowerAndMixedCaseverifying exact-case, lowercase, mixed-case, and missing column name lookups.Expected Impact
Stringandbyte[]allocations when reading non-lowercase column names viaFieldValueList.get(String).Locale.getDefault()lookups on exact-case and lowercase column name hits.HashMaptable resizing duringFieldListconstruction for wide schemas.Verification
FieldListTest,SchemaTest, andFieldValueListTest:mvn test -pl java-bigquery/google-cloud-bigquery -Dtest=FieldListTest,SchemaTest,FieldValueListTest