perf: refactor executePlan to try to avoid constantly entering Tokio runtime #2938
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
N/A.
Rationale for this change
Performance profiling reveals significant execution time spent in
tokio::runtime::Runtime::enter()overhead. The polling loop inexecutePlanwas entering and exiting the Tokio runtime on every iteration, causing significant performance degradation.What changes are included in this PR?
Refactored the polling loop in
Java_org_apache_comet_Native_executePlanto enter the Tokio runtime once for the entire loop instead of on each iteration:get_runtime().block_on()to wrap the entire loop instead of calling it inside the looptokio::task::block_in_place()around JNI calls in thePoll::Pendingbranch to ensure thread safety (JNI env is thread-local and cannot safely migrate between Tokio worker threads)block_in_placeHow are these changes tested?
Existing tests.