Skip to content

Commit

Permalink
merger: don't create key_def/merger for one source
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Totktonada committed Oct 19, 2021
1 parent 3ecc0dd commit 54171b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
testing. It means that methods `crud.min()` and `crud.max` won't work for old
versions (< 1.10.8) anymore.
* Names of errors generated by CRUD operations have been unified.
* Opmimize `crud.select()` / `crud.pairs()` for one replicaset case (say, when
`bucket_id` is passed or deducible from conditions). It gives 13% boost on
the case from #220.

### Fixed

Expand Down
8 changes: 8 additions & 0 deletions crud/select/merger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ local function new(replicasets, space, index_id, func_name, func_args, opts)
table.insert(merger_sources, source)
end

-- Trick for performance.
--
-- No need to create merger, key_def and pass tuples over the
-- merger, when we have only one tuple source.
if #merger_sources == 1 then
return merger_sources[1]
end

local keydef = Keydef.new(space, opts.field_names, index_id)
-- When built-in merger is used with external keydef, `merger_lib.new(keydef)`
-- fails. It's simply fixed by casting `keydef` to 'struct key_def&'.
Expand Down

0 comments on commit 54171b7

Please sign in to comment.