Skip to content

Commit 2f690ba

Browse files
committed
perf: drop wrap_box_space_func_result to cut allocations and speed storage calls
- remove the extra wrapper around box.space methods to avoid per-call closures and arg tables - call wrap_func_result directly so storage paths allocate less and return handling stays centralized - reduce storage-side overhead on replace/insert/delete/get/update/upsert(+_many) for better call latency
1 parent a35f0a8 commit 2f690ba

File tree

12 files changed

+36
-41
lines changed

12 files changed

+36
-41
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Fixed
11+
* drop wrap_box_space_func_result to cut allocations and speed storage calls.
12+
1013
## [1.6.1] - 19-09-25
1114

1215
### Added

crud/borders.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ local function get_border_on_storage(border_name, space_name, index_id, field_na
3636
return index[border_name](index)
3737
end
3838

39-
return schema.wrap_func_result(space, get_index_border, {index}, {
39+
return schema.wrap_func_result(space, get_index_border, {
4040
add_space_schema_hash = true,
4141
field_names = field_names,
4242
fetch_latest_metadata = fetch_latest_metadata,
43-
})
43+
}, index)
4444
end
4545

4646
borders.storage_api = {[STAT_FUNC_NAME] = get_border_on_storage}

crud/common/schema.lua

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,18 @@ function schema.truncate_row_trailing_fields(tuple, field_names)
209209
return tuple
210210
end
211211

212-
function schema.wrap_func_result(space, func, args, opts)
213-
dev_checks('table', 'function', 'table', 'table')
212+
-- schema.wrap_func_result pcalls function
213+
-- and returns its result as a table
214+
-- `{res = ..., err = ..., space_schema_hash = ...}`
215+
-- space_schema_hash is computed if function failed and
216+
-- `add_space_schema_hash` is true
217+
function schema.wrap_func_result(space, func, opts, ...)
218+
dev_checks('table', 'function', 'table')
219+
opts = opts or {}
214220

215221
local result = {}
216222

217-
opts = opts or {}
218-
219-
local ok, func_res = pcall(func, unpack(args))
223+
local ok, func_res = pcall(func, ...)
220224
if ok then
221225
if opts.noreturn ~= true then
222226
result.res = filter_tuple_fields(func_res, opts.field_names)
@@ -246,20 +250,6 @@ function schema.wrap_func_result(space, func, args, opts)
246250
return result
247251
end
248252

249-
-- schema.wrap_box_space_func_result pcalls some box.space function
250-
-- and returns its result as a table
251-
-- `{res = ..., err = ..., space_schema_hash = ...}`
252-
-- space_schema_hash is computed if function failed and
253-
-- `add_space_schema_hash` is true
254-
function schema.wrap_box_space_func_result(space, box_space_func_name, box_space_func_args, opts)
255-
dev_checks('table', 'string', 'table', 'table')
256-
local function func(space, box_space_func_name, box_space_func_args)
257-
return space[box_space_func_name](space, unpack(box_space_func_args))
258-
end
259-
260-
return schema.wrap_func_result(space, func, {space, box_space_func_name, box_space_func_args}, opts)
261-
end
262-
263253
-- schema.result_needs_reload checks that schema reload can
264254
-- be helpful to avoid storage error.
265255
-- It checks if space_schema_hash returned by storage

crud/delete.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ local function delete_on_storage(space_name, key, field_names, opts)
4444

4545
-- add_space_schema_hash is false because
4646
-- reloading space format on router can't avoid delete error on storage
47-
return schema.wrap_box_space_func_result(space, 'delete', {key}, {
47+
return schema.wrap_func_result(space, space.delete, {
4848
add_space_schema_hash = false,
4949
field_names = field_names,
5050
noreturn = opts.noreturn,
5151
fetch_latest_metadata = opts.fetch_latest_metadata,
52-
})
52+
}, space, key)
5353
end
5454

5555
delete.storage_api = {[DELETE_FUNC_NAME] = delete_on_storage}

crud/get.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ local function get_on_storage(space_name, key, field_names, opts)
4343

4444
-- add_space_schema_hash is false because
4545
-- reloading space format on router can't avoid get error on storage
46-
return schema.wrap_box_space_func_result(space, 'get', {key}, {
46+
return schema.wrap_func_result(space, space.get, {
4747
add_space_schema_hash = false,
4848
field_names = field_names,
4949
fetch_latest_metadata = opts.fetch_latest_metadata,
50-
})
50+
}, space, key)
5151
end
5252

5353
get.storage_api = {[GET_FUNC_NAME] = get_on_storage}

crud/insert.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ local function insert_on_storage(space_name, tuple, opts)
4545
-- add_space_schema_hash is true only in case of insert_object
4646
-- the only one case when reloading schema can avoid insert error
4747
-- is flattening object on router
48-
return schema.wrap_box_space_func_result(space, 'insert', {tuple}, {
48+
return schema.wrap_func_result(space, space.insert, {
4949
add_space_schema_hash = opts.add_space_schema_hash,
5050
field_names = opts.fields,
5151
noreturn = opts.noreturn,
5252
fetch_latest_metadata = opts.fetch_latest_metadata,
53-
})
53+
}, space, tuple)
5454
end
5555

5656
insert.storage_api = {[INSERT_FUNC_NAME] = insert_on_storage}

crud/insert_many.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ local function insert_many_on_storage(space_name, tuples, opts)
5757
-- add_space_schema_hash is true only in case of insert_object_many
5858
-- the only one case when reloading schema can avoid insert error
5959
-- is flattening object on router
60-
local insert_result = schema.wrap_box_space_func_result(space, 'insert', {tuple}, {
60+
local insert_result = schema.wrap_func_result(space, space.insert, {
6161
add_space_schema_hash = opts.add_space_schema_hash,
6262
field_names = opts.fields,
6363
noreturn = opts.noreturn,
6464
fetch_latest_metadata = opts.fetch_latest_metadata,
65-
})
65+
}, space, tuple)
6666
if opts.fetch_latest_metadata then
6767
replica_schema_version = insert_result.storage_info.replica_schema_version
6868
end

crud/replace.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ local function replace_on_storage(space_name, tuple, opts)
4545
-- add_space_schema_hash is true only in case of replace_object
4646
-- the only one case when reloading schema can avoid insert error
4747
-- is flattening object on router
48-
return schema.wrap_box_space_func_result(space, 'replace', {tuple}, {
48+
49+
local result = schema.wrap_func_result(space, space.replace, {
4950
add_space_schema_hash = opts.add_space_schema_hash,
5051
field_names = opts.fields,
5152
noreturn = opts.noreturn,
5253
fetch_latest_metadata = opts.fetch_latest_metadata,
53-
})
54+
}, space, tuple)
55+
return result
5456
end
5557

5658
replace.storage_api = {[REPLACE_FUNC_NAME] = replace_on_storage}

crud/replace_many.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ local function replace_many_on_storage(space_name, tuples, opts)
5757
-- add_space_schema_hash is true only in case of replace_object_many
5858
-- the only one case when reloading schema can avoid replace error
5959
-- is flattening object on router
60-
local insert_result = schema.wrap_box_space_func_result(space, 'replace', {tuple}, {
60+
local insert_result = schema.wrap_func_result(space, space.replace, {
6161
add_space_schema_hash = opts.add_space_schema_hash,
6262
field_names = opts.fields,
6363
noreturn = opts.noreturn,
6464
fetch_latest_metadata = opts.fetch_latest_metadata,
65-
})
65+
}, space, tuple)
6666

6767
if opts.fetch_latest_metadata then
6868
replica_schema_version = insert_result.storage_info.replica_schema_version

crud/update.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ local function update_on_storage(space_name, key, operations, field_names, opts)
4444

4545
-- add_space_schema_hash is false because
4646
-- reloading space format on router can't avoid update error on storage
47-
local res, err = schema.wrap_box_space_func_result(space, 'update', {key, operations}, {
47+
local res, err = schema.wrap_func_result(space, space.update, {
4848
add_space_schema_hash = false,
4949
field_names = field_names,
5050
noreturn = opts.noreturn,
5151
fetch_latest_metadata = opts.fetch_latest_metadata,
52-
})
52+
}, space, key, operations)
5353

5454
if err ~= nil then
5555
return nil, err
@@ -66,12 +66,12 @@ local function update_on_storage(space_name, key, operations, field_names, opts)
6666
-- More details: https://github.com/tarantool/tarantool/issues/3378
6767
if utils.is_field_not_found(res.err.code) then
6868
operations = utils.add_intermediate_nullable_fields(operations, space:format(), space:get(key))
69-
res, err = schema.wrap_box_space_func_result(space, 'update', {key, operations}, {
69+
res, err = schema.wrap_func_result(space, space.update, {
7070
add_space_schema_hash = false,
7171
field_names = field_names,
7272
noreturn = opts.noreturn,
7373
fetch_latest_metadata = opts.fetch_latest_metadata,
74-
})
74+
}, space, key, operations)
7575
end
7676

7777
return res, err

0 commit comments

Comments
 (0)