From 54171b757185326ab498c24e9a1d25f139b42ec0 Mon Sep 17 00:00:00 2001 From: Alexander Turenko Date: Tue, 19 Oct 2021 03:16:32 +0300 Subject: [PATCH] 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 --- CHANGELOG.md | 3 +++ crud/select/merger.lua | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cb7495d..81735362 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/crud/select/merger.lua b/crud/select/merger.lua index 66b6e19e..fa443b84 100644 --- a/crud/select/merger.lua +++ b/crud/select/merger.lua @@ -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&'.