Caideyipi opened a new pull request, #18195:
URL: https://github.com/apache/iotdb/pull/18195

   ## Description
   
   ### Problem
   
   An async-profiler CPU profile of an `insertRecords` workload with Pipe 
enabled showed that synchronous Pipe event construction dominated the sampled 
write path:
   
   - `PipeInsertionDataNodeListener.listenToInsertNode` accounted for 1725 of 
3614 total samples (47.73%).
   - This was about 95.2% of the sampled `insertRecords` request branch.
   - Most self time was under `Stream.distinct()`, especially `HashMap.resize` 
and `HashMap.putVal`.
   
   For every additional row of the same device, the previous implementation 
rebuilt a Stream, a distinct set, and a result array from the accumulated and 
new measurements. This causes heavy temporary allocation for identical schemas 
and repeated scans when the measurement union grows.
   
   ### Changes
   
   - Keep the original measurement array for devices that occur only once.
   - Create one `LinkedHashSet` only when a device repeats, preserving 
encounter order.
   - Reuse that set for subsequent heterogeneous schemas and materialize the 
result array once.
   - Skip set insertion when a later schema equals the first schema.
   - Preserve the previous null-array failure behavior and support null 
measurement elements used by partial inserts.
   - Add a unit test covering identical and heterogeneous schemas, order, 
multiple devices, duplicate measurements, and null measurement elements.
   
   All aggregation containers remain method-local; shared-state and concurrency 
behavior are unchanged.
   
   ### Validation
   
   - `mvn spotless:apply -pl iotdb-core/datanode`
   - DataNode Checkstyle: 0 violations
   - Java 17 isolated compilation of the changed production and test classes
   - `TsFileEpochManagerTest`: `OK (1 test)`
   
   The full single-module Maven test could not reach this test because the 
local workspace has stale cross-module/generated artifacts (missing unrelated 
current master symbols such as `TimePartitionProgressIndex` and generated 
parser/fill classes). CI should provide the clean-reactor verification.
   
   <hr>
   
   This PR has:
   - [x] been self-reviewed.
   - [x] added comments explaining the performance-sensitive design.
   - [x] added unit tests for the new aggregation path.
   
   <hr>
   
   ##### Key changed/added classes
   
   - `TsFileEpochManager`
   - `TsFileEpochManagerTest`


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to