Skip to content

box: speed up tuple_new() for large sparse tuples by 3.5x#9793

Merged
sergepetrenko merged 4 commits intotarantool:masterfrom
Gumix:iverbin/gh-711-optimize-validation-of-sparse-tuples-in-memcs
Mar 18, 2024
Merged

box: speed up tuple_new() for large sparse tuples by 3.5x#9793
sergepetrenko merged 4 commits intotarantool:masterfrom
Gumix:iverbin/gh-711-optimize-validation-of-sparse-tuples-in-memcs

Conversation

@Gumix
Copy link
Contributor

@Gumix Gumix commented Mar 11, 2024

The first 2 patches add the bench_tuple_new<FORMAT_SPARSE> benchmark, that creates sparse tuples (1K fields each, 990 of which are nils).

The next 2 patches speed up the benchmark from 7 μs to 2 μs per iteration.

Needed for tarantool/tarantool-ee#711

@Gumix Gumix requested a review from a team as a code owner March 11, 2024 16:41
@coveralls
Copy link

coveralls commented Mar 11, 2024

Coverage Status

coverage: 86.948% (-0.06%) from 87.007%
when pulling dad86b1 on Gumix:iverbin/gh-711-optimize-validation-of-sparse-tuples-in-memcs
into 3978d54
on tarantool:master
.

@locker locker assigned Gumix and unassigned locker Mar 12, 2024
Currently `class MpData` generates msgpack data with a predefined format,
let's call it `FORMAT_BASIC`. This patch allows to extend it with other
formats. No functional changes.

Needed for tarantool/tarantool-ee#711

NO_DOC=perf test
NO_TEST=perf test
NO_CHANGELOG=perf test
@Gumix Gumix requested a review from a team as a code owner March 12, 2024 18:33
@Gumix Gumix changed the title box: speed up tuple_new() for large sparse tuples by 2~3x box: speed up tuple_new() for large sparse tuples by 3.5x Mar 12, 2024
@Gumix Gumix requested a review from locker March 12, 2024 19:26
@Gumix Gumix assigned locker and unassigned Gumix Mar 12, 2024
@locker locker assigned Gumix and unassigned locker Mar 13, 2024
Gumix added 3 commits March 13, 2024 15:23
Implement `class MpData<FORMAT_SPARSE>`, which generates 1000 fields,
10 of them contain unsigned integers, while the remaining are null.

Needed for tarantool/tarantool-ee#711

NO_DOC=perf test
NO_TEST=perf test
NO_CHANGELOG=perf test
It is possible to skip MP_NIL by mp_decode_nil(), which is faster than
mp_next(). This patch improves bench_tuple_new<FORMAT_SPARSE> by 2.2x.

NO_WRAP
$ taskset 0x2 ~/benchmark/tools/compare.py benchmarks \
  ./tuple.perftest.old ./tuple.perftest.new \
  --benchmark_min_warmup_time=10 \
  --benchmark_repetitions=30 \
  --benchmark_report_aggregates_only=true \
  --benchmark_filter=tuple_new\<FORMAT_SPARSE\>
[...]
Comparing ./tuple.perftest.old to ./tuple.perftest.new
Benchmark                                               Time             CPU      Time Old      Time New       CPU Old       CPU New
------------------------------------------------------------------------------------------------------------------------------------
bench_tuple_new<FORMAT_SPARSE>_mean                  -0.5525         -0.5525          6985          3126          6985          3126
bench_tuple_new<FORMAT_SPARSE>_median                -0.5445         -0.5444          6838          3115          6838          3115
bench_tuple_new<FORMAT_SPARSE>_stddev                -0.8368         -0.8367           541            88           541            88
bench_tuple_new<FORMAT_SPARSE>_cv                    -0.6354         -0.6352             0             0             0             0
NO_WRAP

Needed for tarantool/tarantool-ee#711

NO_DOC=perf improvement
NO_TEST=perf improvement
NO_CHANGELOG=next commit
If the number of tuple fields is less than `format->min_field_count`,
then some required field is missed, i.e., there is no need to update the
`required_fields` bitmap during msgpack decoding. This optimization is
valid only if tuple format doesn't contain fields accessed by JSON paths.

This patch improves bench_tuple_new by 15-50%, depending on field count.

NO_WRAP
$ taskset 0x2 ~/benchmark/tools/compare.py benchmarks \
  ./tuple.perftest.old ./tuple.perftest.new \
  --benchmark_min_warmup_time=10 \
  --benchmark_repetitions=30 \
  --benchmark_report_aggregates_only=true \
  --benchmark_filter=tuple_new
[...]
Comparing ./tuple.perftest.old to ./tuple.perftest.new
Benchmark                                               Time             CPU      Time Old      Time New       CPU Old       CPU New
------------------------------------------------------------------------------------------------------------------------------------
bench_tuple_new<FORMAT_BASIC>_mean                   -0.1469         -0.1470           126           107           126           107
bench_tuple_new<FORMAT_BASIC>_median                 -0.1428         -0.1429           124           106           124           106
bench_tuple_new<FORMAT_BASIC>_stddev                 +0.0589         +0.0600             4             5             4             5
bench_tuple_new<FORMAT_BASIC>_cv                     +0.2412         +0.2427             0             0             0             0
bench_tuple_new<FORMAT_SPARSE>_mean                  -0.3754         -0.3753          3104          1939          3104          1939
bench_tuple_new<FORMAT_SPARSE>_median                -0.3749         -0.3747          3071          1920          3071          1920
bench_tuple_new<FORMAT_SPARSE>_stddev                -0.3482         -0.3482            85            55            85            55
bench_tuple_new<FORMAT_SPARSE>_cv                    +0.0434         +0.0434             0             0             0             0
NO_WRAP

Needed for tarantool/tarantool-ee#711

NO_DOC=perf improvement
@Gumix Gumix assigned sergepetrenko and unassigned Gumix Mar 13, 2024
Copy link
Collaborator

@sergepetrenko sergepetrenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch!

@sergepetrenko sergepetrenko added the full-ci Enables all tests for a pull request label Mar 14, 2024
@sergepetrenko sergepetrenko merged commit 26bf1cb into tarantool:master Mar 18, 2024
@Gumix Gumix mentioned this pull request May 13, 2024
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Enables all tests for a pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants