You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "jt2594838 (via GitHub)" <gi...@apache.org> on 2026/07/22 07:05:17 UTC
[PR] [Performance] Allocate AlignedTVList primitive arrays lazily [iotdb]
jt2594838 opened a new pull request, #18276:
URL: https://github.com/apache/iotdb/pull/18276
## Description
Follow-up to #18264. This PR contains only the lazy primitive-array allocation changes on top of the merged dynamic-bitmap implementation.
- Keep `null` placeholders for newly added or unwritten aligned columns and allocate each `PrimitiveArray` only on its first actual write.
- Update `TsFileProcessor` memory accounting for lazy primitive-array allocation.
- Cover clone/read/WAL/null-tablet paths with unit tests.
- Add a 256 MiB integration test that writes 40,000 rows to one aligned measurement and then one row to 1,200 new measurements, preventing the eager-allocation memory failure.
- Add a real 1C1D integration performance comparison against a master worktree, including both sparse/lazy-column and fully non-null aligned-tablet workloads, and generate a Markdown report.
## Performance
Compared master `91476b0df7` with candidate `b7f846ec98`:
| Workload | master | candidate | Result |
| --- | ---: | ---: | ---: |
| Sparse/lazy columns | 30.598 ms | 14.294 ms | latency -53.29%, throughput +114.07% |
| Fully non-null aligned tablets | 123.767 ms | 123.359 ms | +0.33% |
## Tests
- AlignedTVList unit tests: 14/14 passed.
- 256 MiB low-memory integration test passed (40,000 historical rows, then one row across 1,200 new columns).
- 1C1D worktree comparison completed for master and candidate, including the no-null workload.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Performance] Allocate AlignedTVList primitive arrays lazily [iotdb]
Posted by "HTHou (via GitHub)" <gi...@apache.org>.
HTHou commented on code in PR #18276:
URL: https://github.com/apache/iotdb/pull/18276#discussion_r3628747530
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/TsFileProcessor.java:
##########
@@ -1124,13 +1132,21 @@ private void updateAlignedMemCost(
+ (newPointNum % PrimitiveArrayManager.ARRAY_SIZE > 0 ? 1 : 0);
long acquireArray = newArrayCnt - currentArrayCnt;
+ boolean writesExistingLastBlock =
+ currentPointNum % PrimitiveArrayManager.ARRAY_SIZE != 0 && incomingPointNum > 0;
+ for (TSDataType dataType : dataTypesInTVList) {
+ if (writesExistingLastBlock) {
+ memIncrements[0] += AlignedTVList.primitiveArrayMemCost(dataType);
+ }
+ // Reserve a bitmap as well as a value array for new blocks because the tablet may contain
+ // null or failed rows in those blocks.
+ memIncrements[0] += acquireArray * AlignedTVList.valueListArrayMemCost(dataType);
+ }
+
if (acquireArray != 0) {
// memory of extending the TVList
memIncrements[0] +=
acquireArray * alignedMemChunk.getWorkingTVList().alignedTvListArrayMemCost();
- for (TSDataType dataType : dataTypesInTVList) {
- memIncrements[0] += acquireArray * AlignedTVList.valueListArrayMemCost(dataType);
- }
}
Review Comment:
This still charges the dense per-block cost for every existing column whenever a new block is acquired, while AlignedTVList.expandValues() now only adds null placeholders and allocates primitive arrays on their first actual write.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Performance] Allocate AlignedTVList primitive arrays lazily [iotdb]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #18276:
URL: https://github.com/apache/iotdb/pull/18276#issuecomment-5045207912
## [](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=18276) **Quality Gate failed**
Failed conditions
 [E Reliability Rating on New Code](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=18276) (required ≥ A)
<!-- sqra:qg_revision=e382eebc27a0b113dbce459661149310876fb2c2ee6b7a9ebd97a619132a6c55 -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=18276)
##
💡 **Need a hand with PR review?** Try [Gitar by Sonar](https://gitar.ai/?utm_source=sonarqube-cloud&utm_medium=in-product&utm_campaign=gitar-crosssell-q3-2026&utm_content=pr-deco)!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Performance] Allocate AlignedTVList primitive arrays lazily [iotdb]
Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on PR #18276:
URL: https://github.com/apache/iotdb/pull/18276#issuecomment-5044701977
Added regression coverage in commit [`27e985663b5`](https://github.com/apache/iotdb/commit/27e985663b5) for the two memory-accounting issues noted above.
Both tests intentionally fail on the current PR head:
```text
TsFileProcessorTest#testAlignedSparseRowDoesNotChargeUnallocatedPrimitiveArrayOnNewBlock
expected:<272> but was:<0>
AlignedTVListTest#testCalculateRamSizeExcludesUnallocatedPrimitiveArrays
expected:<2384> but was:<3440>
```
The second mismatch is 1056 bytes, exactly two unallocated INT64 primitive arrays (2 blocks x 528 bytes). The first shows that a sparse row and a dense row crossing the same block boundary are currently charged the same increment, although the dense row materializes one additional INT32 primitive array (272 bytes).
Besides `calculateRamSize()`, the dense per-block charge appears in all three write paths in `TsFileProcessor`: single-row around line 852, `InsertRows` around line 951, and Tablet around line 1149. The regression tests should turn green once those paths charge only primitive arrays that are actually materialized.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Performance] Allocate AlignedTVList primitive arrays lazily [iotdb]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #18276:
URL: https://github.com/apache/iotdb/pull/18276#issuecomment-5044817450
## [](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=18276) **Quality Gate failed**
Failed conditions
 [E Reliability Rating on New Code](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=18276) (required ≥ A)
<!-- sqra:qg_revision=eb9d6317a98cb40f3115444a4ed0e858c92a40bc38326b9dd88076c3df7bb982 -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=18276)
##
💡 **Need a hand with PR review?** Try [Gitar by Sonar](https://gitar.ai/?utm_source=sonarqube-cloud&utm_medium=in-product&utm_campaign=gitar-crosssell-q3-2026&utm_content=pr-deco)!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Performance] Allocate AlignedTVList primitive arrays lazily [iotdb]
Posted by "jt2594838 (via GitHub)" <gi...@apache.org>.
jt2594838 commented on code in PR #18276:
URL: https://github.com/apache/iotdb/pull/18276#discussion_r3629717438
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java:
##########
Review Comment:
Thanks, fixed in a3351070. AlignedTVList now updates materializedValueArrayMemCost when getOrCreateValueArray() allocates a primitive array. calculateRamSize() uses the per-block cost without value primitive arrays plus the incrementally tracked materialized-array cost, so it no longer assumes dense value arrays or scans all blocks. The tracked state is also handled by clone, projection, column extension, and clear paths.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/TsFileProcessor.java:
##########
@@ -1124,13 +1132,21 @@ private void updateAlignedMemCost(
+ (newPointNum % PrimitiveArrayManager.ARRAY_SIZE > 0 ? 1 : 0);
long acquireArray = newArrayCnt - currentArrayCnt;
+ boolean writesExistingLastBlock =
+ currentPointNum % PrimitiveArrayManager.ARRAY_SIZE != 0 && incomingPointNum > 0;
+ for (TSDataType dataType : dataTypesInTVList) {
+ if (writesExistingLastBlock) {
+ memIncrements[0] += AlignedTVList.primitiveArrayMemCost(dataType);
+ }
+ // Reserve a bitmap as well as a value array for new blocks because the tablet may contain
+ // null or failed rows in those blocks.
+ memIncrements[0] += acquireArray * AlignedTVList.valueListArrayMemCost(dataType);
+ }
+
if (acquireArray != 0) {
// memory of extending the TVList
memIncrements[0] +=
acquireArray * alignedMemChunk.getWorkingTVList().alignedTvListArrayMemCost();
- for (TSDataType dataType : dataTypesInTVList) {
- memIncrements[0] += acquireArray * AlignedTVList.valueListArrayMemCost(dataType);
- }
}
Review Comment:
Thanks, fixed in a3351070. The aligned row, rows, and tablet estimators now split the charge into: (1) the base aligned-TVList block cost without value primitive arrays, (2) placeholder/bitmap cost for newly extended columns, and (3) primitive-array cost only when a successful non-null write first materializes that column/block. Sparse, null, and failed-write paths are covered by tests; the tablet path also skips per-row checks when both bitmap and results are absent.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Performance] Allocate AlignedTVList primitive arrays lazily [iotdb]
Posted by "HTHou (via GitHub)" <gi...@apache.org>.
HTHou commented on code in PR #18276:
URL: https://github.com/apache/iotdb/pull/18276#discussion_r3628732238
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java:
##########
Review Comment:
calculateRamSize() still multiplies the number of timestamp blocks by alignedTvListArrayMemCost(), which assumes that every column has a materialized primitive array in every block. That assumption is no longer valid after this change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Performance] Allocate AlignedTVList primitive arrays lazily [iotdb]
Posted by "jt2594838 (via GitHub)" <gi...@apache.org>.
jt2594838 merged PR #18276:
URL: https://github.com/apache/iotdb/pull/18276
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org