lower segment heap footprint and fix bug with expression type coercion#14002
Merged
clintropolis merged 2 commits intoapache:masterfrom Mar 31, 2023
Merged
Conversation
imply-cheddar
approved these changes
Mar 31, 2023
| { | ||
| private static final Interner<String> STRING_INTERNER = Interners.newWeakInterner(); | ||
| /** | ||
| * Interner for smoosh internal files, which includes all column names since very column has an internal file |
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.
Description
While working on some other stuff I noticed that we were doing something when loading segments which results in some extra heap usage storing redundant stuff we don't really need. Specifically, the changes in #12279 causes us to make a combined column and dimension list in the form of
Indexedto pass to theSimpleQueryableIndex, which it was doing prior to this PR with https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/segment/IndexIO.java#L648GenericIndexed.fromIterablewhich is going to make new heap bytebuffers of the column and dimension lists. The columnsIndexedis thrown away basically, but the dimensions list is kept around forever.We actually already have to have all of these column names on heap, and are already interning them via the
FileSmooshMapperhttps://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/java/util/common/io/smoosh/SmooshedFileMapper.java#L88 which does so whenever it readsmeta.smooshto get the internal file list of a smoosh. There is an internal file as the entry point for every column name, so if we re-use this interner for the map ofColumnHoldersuppliers as well as to back theIndexed<String>for the dimension list then we can save some heap.With my laptop test cluster of ~5k segments it reduces the heap footprint by ~20MB
Before:

After:

Looking specifically at strings, we now have about 1/3 as many on heap (from the map of ColumnHolder suppliers), not counting all of the heap bytebuffers which were backing the dimensions lists.


Completely unrelated, this PR also fixes a bug with native expression type coercion with complex types. The added test would fail where it would return "unknown complex" sometimes when using the
ExpressionTypeCoercion.operatormethod. I guess I could have made it its own PR, but both things were small...This PR has: