Skip to content

Conversation

@shuwenwei
Copy link
Member

@shuwenwei shuwenwei commented Nov 17, 2025

Description

Default slowQueryThreshold should be 10s

截屏2025-11-17 11 49 57

optimize encodeBatch for multi tvlist scene

Scenario

Rows: 0–99999 (100,000 rows)
Duplicate timestamps occur at only two positions:

index 123

index 90732

Using regular BitMap

Must allocate 100,000 bits immediately.

Even though only 2 bits will be marked.

Using LazyBitMap (blockSize = 10,000)

LazyBitMap creates blocks only when needed:

Block for index 123 → block index = 0

Block for index 90732 → block index = 90

Total allocated blocks: 2 blocks
Each block has only 10,000 bits, so memory is:

2 blocks × 10,000 bits = 20,000 bits total

Savings

Regular BitMap: 100,000 bits
LazyBitMap: 20,000 bits

➡ 80% memory reduction
➡ Matches the sparse nature of duplicated timestamps

@codecov
Copy link

codecov bot commented Nov 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 38.75%. Comparing base (a7f1527) to head (9ec284e).
⚠️ Report is 17 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #16765      +/-   ##
============================================
+ Coverage     38.72%   38.75%   +0.03%     
  Complexity      207      207              
============================================
  Files          5005     5006       +1     
  Lines        331856   332051     +195     
  Branches      42201    42227      +26     
============================================
+ Hits         128498   128675     +177     
- Misses       203358   203376      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shuwenwei shuwenwei changed the title Fix slowQueryThreshold Fix slowQueryThreshold & optimize encodeBatch Nov 20, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces two key improvements: changing the default slowQueryThreshold from 30 seconds to 10 seconds, and optimizing memory usage in encodeBatch by replacing BitMap with LazyBitMap for tracking duplicate timestamps in sparse scenarios.

  • Changed default slow query threshold from 30s to 10s to align with documented defaults
  • Introduced LazyBitMap optimization to reduce memory allocation by up to 80% when tracking sparse duplicate timestamps
  • Added test coverage for the encodeBatch functionality with multiple TVList scenarios

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
IoTDBConfig.java Updated default slowQueryThreshold from 30000ms to 10000ms
AlignedTVList.java Replaced BitMap with LazyBitMap in encodeBatch method; added @SuppressWarnings annotations for cognitive complexity
AlignedTVListIteratorTest.java Added new testEncodeBatch test method to verify encodeBatch functionality with different TVList configurations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

} else {
if (Objects.isNull(timeDuplicateInfo)) {
timeDuplicateInfo = new BitMap(rows);
timeDuplicateInfo = new LazyBitMap(index, maxRowCountOfCurrentBatch, rows - 1);
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The LazyBitMap is initialized with index as the startPosition, but later at line 2206, the code iterates from startIndex (saved at line 2160) to check isMarked(sortedRowIndex) at line 2220. If the first duplicate is found after some iterations, sortedRowIndex could be less than index, causing incorrect behavior. The first parameter should be startIndex instead of index to align with the iteration range at line 2206.

Example: If startIndex=0 and the first duplicate is at index=50, LazyBitMap(50,...) is created, but isMarked(0) through isMarked(49) will be called, which are below the startPosition.

Suggested change
timeDuplicateInfo = new LazyBitMap(index, maxRowCountOfCurrentBatch, rows - 1);
timeDuplicateInfo = new LazyBitMap(startIndex, maxRowCountOfCurrentBatch, rows - 1);

Copilot uses AI. Check for mistakes.
…ngine/dataregion/memtable/AlignedTVListIteratorTest.java

Co-authored-by: Copilot <[email protected]>
@sonarqubecloud
Copy link

@JackieTien97 JackieTien97 merged commit 03b60d1 into master Nov 25, 2025
31 checks passed
@JackieTien97 JackieTien97 deleted the fixSlowQueryThreshold branch November 25, 2025 10:18
JackieTien97 pushed a commit that referenced this pull request Nov 26, 2025
alpass163 pushed a commit to alpass163/iotdb that referenced this pull request Nov 28, 2025
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