Avoid thread fanout for single-item parallel maps#1160
Merged
Conversation
f2bb494 to
a223d8e
Compare
myronmarston
requested changes
Apr 30, 2026
Collaborator
myronmarston
left a comment
There was a problem hiding this comment.
👏 Great find! Left a few minor nits.
a223d8e to
32550f1
Compare
myronmarston
approved these changes
Apr 30, 2026
32550f1 to
c9d763f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
ElasticGraph::Support::Threading.parallel_mapuses normalmapfor exactly one itemsizeContext
This avoids creating a Ruby thread for single-client msearch fanout, which is common for deployments that route queries through one datastore cluster.
Benchmark
bundle exec ruby benchmarks/threading/parallel_map_single_item.rb3.56M i/svs before24.3k i/s(146xfaster)3.23M i/svs before27.6k i/s(117xfaster)Thread.newcalls for 1,000 single-item maps: before1000, after0208.29nsvs128.74ns) because it pays the one-item shape check, but neither path creates threadsTesting
bundle exec rspec elasticgraph-support/spec/unit/elastic_graph/support/threading_spec.rbscript/run_gem_specs elasticgraph-supportscript/lint elasticgraph-support/lib/elastic_graph/support/threading.rb elasticgraph-support/spec/unit/elastic_graph/support/threading_spec.rb benchmarks/threading/parallel_map_single_item.rbscript/type_checkbundle exec ruby benchmarks/threading/parallel_map_single_item.rbGenerated with Codex