Skip to content

[Performance] Stop pre-sizing memtable block containers - #19426

Closed
luoluoyuyu wants to merge 1 commit into
apache:masterfrom
luoluoyuyu:fix/tvlist-block-preallocation
Closed

luoluoyuyu wants to merge 1 commit into
apache:masterfrom
luoluoyuyu:fix/tvlist-block-preallocation

Conversation

@luoluoyuyu

@luoluoyuyu luoluoyuyu commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Summary

A memtable list sized its block containers with the node-wide average series length
(WritingMetrics#getGlobalAvgSeriesPointNum() / ARRAY_SIZE), which has no upper bound and is
unrelated to the number of blocks a list holds. It was applied to every container:
AlignedTVList pre-allocated one Object[average] per column (even for columns never written),
extendColumns materialized a null per open block and column, and the unaligned
timestamps/indices/bitMap containers were pre-sized the same way. The capacity was also
invisible to calculateContainerRamCost (charged by list.size()).

Changes

  • LazyValueColumn: aligned per-column block container. A slot stays an implicit null and is
    allocated on first write; size() still equals the number of open blocks, so write, sort, clone,
    WAL and flush-encode paths are unchanged.
  • AlignedTVList constructor and extendColumns use it instead of pre-filled ArrayLists.
  • Pre-allocation is now the hot-reloadable switch enable_tvlist_block_preallocation
    (default false; when enabled, a fixed 16 blocks). Removed the global accumulators in
    WritingMetrics that only fed that average; the per-DataRegion AVG_SERIES_POINT_NUM metric is
    unchanged.
  • Container accounting charges the retained slots (LazyValueColumn#ramCost()).

Example

A column never written, global average 160 blocks:

Before After
Retained by the container list + Object[160] ≈ 1.3 KB (8-byte refs) container only, 24–32 B
Charged to mem-control size() = 0 actually retained

Config

# default false
enable_tvlist_block_preallocation=false

effectiveMode: hot_reload; read on every list creation.

Validation

mvn -pl iotdb-core/datanode test -Dtest='AlignedTVListTest,PropertiesTest,TsFileProcessorTest,AlignedWritableMemChunkTest,AlignedTVListIteratorTest,NonAlignedTVListIteratorTest,MemTableFlushTaskTest'
plus the TVList tests: 189 + 63 cases, 0 failures.

New tests: testUnwrittenColumnsRetainNoBlockStorage, testUnwrittenColumnKeepsBlockSlotsImplicit,
testExtendColumnsDoesNotAllocatePerBlockSlots, testBlockPreallocationSwitch,
testTVListBlockPreallocationConfiguration.

Data, serialization format, WAL and query results are unchanged.

TVList sized the block containers of a memtable list with the node-wide average
series length (WritingMetrics#getGlobalAvgSeriesPointNum() / ARRAY_SIZE). That
average describes a whole series lifetime rather than the number of blocks a
memtable list holds, it had no upper bound, and it was applied to every
container:

- every measurement column of an aligned TVList pre-allocated one
  Object[average] (about 1.3 KB for 160 blocks) even when the column was never
  written, which dominated the memory of wide devices;
- extendColumns materialized one null reference per open block and column;
- the unaligned timestamps/indices/bitmap containers were pre-sized the same way.

Aligned columns now use LazyValueColumn: a block slot stays an implicit null
until the block receives a value array, so an unwritten column costs only its
container and a null block costs nothing.

Block pre-allocation is now an opt-in, hot-reloadable switch
(enable_tvlist_block_preallocation, default false) with a small fixed bound, and
the container accounting charges the slots that exist, so the memtable cost used
by flush and mem-control matches the memory that is actually retained.
@luoluoyuyu luoluoyuyu changed the title [Performance] Stop pre-sizing memtable block containers for wide devices [Performance] Stop pre-sizing memtable block containers Nov 27, 2026
@luoluoyuyu

Copy link
Copy Markdown
Member Author

Superseded by #19310, which now contains the memtable block-container fix (lazy allocation, opt-in pre-allocation switch, exact container accounting) together with the aligned write-path optimizations.

@luoluoyuyu luoluoyuyu closed this Nov 27, 2026
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.

1 participant