[improve][broker] Improve no-filter dispatch performance by skipping filter calls#26056
[improve][broker] Improve no-filter dispatch performance by skipping filter calls#26056void-ptr974 wants to merge 2 commits into
Conversation
ab3f3eb to
08414a3
Compare
08414a3 to
c487ddb
Compare
c487ddb to
ba8c764
Compare
…ilter-fast-path # Conflicts: # pulsar-broker/src/test/java/org/apache/pulsar/broker/service/AbstractBaseDispatcherTest.java
| filteredBytesCount += metadataAndPayload.readableBytes(); | ||
| entry.release(); | ||
| continue; | ||
| if (hasFilter) { |
There was a problem hiding this comment.
there's a if (hasFilter) { line a few lines above. join the blocks
The results seem odd since I think that results might be flawed. Please check a recent blog post https://quarkus.io/blog/when-the-jit-cant-keep-up/ by Francesco Nigro. The url line has "when the JIT can't keep up". It might be a bottleneck in your case. Claude review for JMH parameters
Some other details from Claude:
It's possible to mitigate issues, but micro benchmarking on Linux x86-64 on a modern CPU with CPU powersaving etc. turned off would have less measurement noise. |
Motivation
AbstractBaseDispatcher#filterEntriesForConsumeris on the dispatch hot path. When no entry filters are configured,runFiltersForEntryonly returnsACCEPT, so calling it once per entry is avoidable work.Modifications
runFiltersForEntrywhen no entry filters are configured.Scope
This intentionally leaves the filtered/redelivery list allocation and ack-set handling unchanged. Those are separate optimizations and are kept out of this PR to make the review focused on the no-filter fast path only.
Performance
This improves no-filter dispatch performance by removing one no-op filter call and the REJECT/RESCHEDULE checks per entry when no filters are configured. Allocation remains effectively unchanged; this is a CPU-path optimization.
JMH data gathered locally using a local-only
DispatcherDispatchPathBenchmark.(noFilterRunFiltersPerEntry|noFilterFastPath)benchmark, with-p entriesCount=32,256,1000 -p batchSize=1,10 -wi 2 -i 5 -w 1s -r 1s -f 1 -bm avgt -tu ns -prof gc:Verification
AbstractBaseDispatcherTestcoverage for a 512-entry no-filter dispatch batch with varying payload sizes and batch sizes../gradlew :pulsar-broker:compileJava :pulsar-broker:checkstyleMain --max-workers=1./gradlew :pulsar-broker:test --tests org.apache.pulsar.broker.service.AbstractBaseDispatcherTest --max-workers=1 -PtestRetryCount=0./gradlew :pulsar-broker:checkstyleTest --max-workers=1