Skip to content

Commit d029cd7

Browse files
committed
merger: don't create key_def/merger for one source
A merge source has the same API as merger itself, so there is no difference in behaviour between a merger created from one source and this source itself. However there is no overhead for creating key_def, merger and passing tuples over the merger. This optimization gives me 13% boost on the case from #220. Follows up #220
1 parent 3ecc0dd commit d029cd7

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1515
testing. It means that methods `crud.min()` and `crud.max` won't work for old
1616
versions (< 1.10.8) anymore.
1717
* Names of errors generated by CRUD operations have been unified.
18+
* Opmimize `crud.select()` / `crud.pairs()` for one replicaset case (say, when
19+
`bucket_id` is passed or deducible from conditions). It gives 13% boost on
20+
the case from #220.
1821

1922
### Fixed
2023

crud/select/merger.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ local function new(replicasets, space, index_id, func_name, func_args, opts)
163163
table.insert(merger_sources, source)
164164
end
165165

166+
-- Trick for performance.
167+
--
168+
-- No need to create merger, key_def and pass tuples over the
169+
-- merger, when we have only one tuple source.
170+
if #merger_sources == 1 then
171+
return merger_sources[1]
172+
end
173+
166174
local keydef = Keydef.new(space, opts.field_names, index_id)
167175
-- When built-in merger is used with external keydef, `merger_lib.new(keydef)`
168176
-- fails. It's simply fixed by casting `keydef` to 'struct key_def&'.

0 commit comments

Comments
 (0)