Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimze append #249

Merged
merged 5 commits into from Oct 27, 2020
Merged

Optimze append #249

merged 5 commits into from Oct 27, 2020

Conversation

Fabianexe
Copy link
Contributor

The append function is slow compared to the get and set method. The reason for this is that unnecessary copies of the data are done in the process. Namely, the get copy the data and the list append a second time. This leads to high allocation numbers and slow runtime overall.
In this PR the number of copies in the process is minimized without touching the BytesQueue logic. This reduces the allocs and halves the runtime of append without changing on the interface.
Some benchmarks result:

name                          old time/op    new time/op    delta
AppendToCache/1-shards-12       8.37µs ±26%    4.06µs ±23%  -51.48%  (p=0.000 n=99+98)
AppendToCache/512-shards-12     3.23µs ± 6%    1.87µs ± 3%  -42.00%  (p=0.000 n=96+92)
AppendToCache/1024-shards-12    3.49µs ± 4%    2.06µs ± 4%  -40.86%  (p=0.000 n=100+93)
AppendToCache/8192-shards-12    4.04µs ± 3%    2.85µs ± 3%  -29.42%  (p=0.000 n=96+97)

name                          old alloc/op   new alloc/op   delta
AppendToCache/1-shards-12       28.1kB ± 0%    14.1kB ± 0%  -49.84%  (p=0.000 n=100+100)
AppendToCache/512-shards-12     28.2kB ± 1%    14.1kB ± 0%  -49.92%  (p=0.000 n=93+95)
AppendToCache/1024-shards-12    29.4kB ± 4%    14.4kB ± 4%  -50.96%  (p=0.000 n=100+94)
AppendToCache/8192-shards-12    34.0kB ± 2%    19.4kB ± 3%  -43.07%  (p=0.000 n=99+98)

name                          old allocs/op  new allocs/op  delta
AppendToCache/1-shards-12         21.0 ± 0%       2.0 ± 0%  -90.48%  (p=0.000 n=100+100)
AppendToCache/512-shards-12       22.0 ± 0%       3.0 ± 0%  -86.36%  (p=0.000 n=100+100)
AppendToCache/1024-shards-12      22.0 ± 0%       3.0 ± 0%  -86.36%  (p=0.000 n=100+100)
AppendToCache/8192-shards-12      22.0 ± 0%       3.0 ± 0%  -86.36%  (p=0.000 n=100+100)

Copy link
Collaborator

@siennathesane siennathesane left a comment

Choose a reason for hiding this comment

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

Nice change! Happy to it, thanks!

@siennathesane siennathesane merged commit 9949a06 into allegro:master Oct 27, 2020
siennathesane pushed a commit that referenced this pull request Nov 4, 2020
* Fix iterator styling issues (#247)

Issues reported in #246

* fix #160 (#246)

* Update to latest golang (#248)

Co-authored-by: Oleg Kovalov <iamolegkovalov@gmail.com>

* inital prep for v3.

Signed-off-by: Mike Lloyd <mike@reboot3times.org>

* Use uint64 intead of uint32

There are posibility we run into a problem of int32 overflow.
To prevent this let's use uint64 everywhere.

https://github.com/allegro/bigcache/blob/21e5ca5c3d539f94e8dc563350acd97c5400154f/shard.go#L138

Fixes: #148

* Fix CI

* Do not run on 1.13

* Do not run long test

* Optimze append (#249)

* Add Benchmark for append

* Optimize Append and halve byte copies

* Optimize Append by reducing allocs

* Optimize Append by reducing allocs

* Reduces allocs from test construct

Co-authored-by: Fabian Gärtner <fabian.gaertner@check24.de>

Co-authored-by: S@P <lorenzotorracchi@mail.com>
Co-authored-by: Oleg Kovalov <iamolegkovalov@gmail.com>
Co-authored-by: Mike Lloyd <mlloyd@rts.com>
Co-authored-by: Fabianexe <Fabianexe@gmail.com>
Co-authored-by: Fabian Gärtner <fabian.gaertner@check24.de>
siennathesane pushed a commit that referenced this pull request Nov 4, 2020
* Fix iterator styling issues (#247)

Issues reported in #246

* fix #160 (#246)

* Update to latest golang (#248)

Co-authored-by: Oleg Kovalov <iamolegkovalov@gmail.com>

* inital prep for v3.

Signed-off-by: Mike Lloyd <mike@reboot3times.org>

* Use uint64 intead of uint32

There are posibility we run into a problem of int32 overflow.
To prevent this let's use uint64 everywhere.

https://github.com/allegro/bigcache/blob/21e5ca5c3d539f94e8dc563350acd97c5400154f/shard.go#L138

Fixes: #148

* Fix CI

* Do not run on 1.13

* Do not run long test

* Optimze append (#249)

* Add Benchmark for append

* Optimize Append and halve byte copies

* Optimize Append by reducing allocs

* Optimize Append by reducing allocs

* Reduces allocs from test construct

Co-authored-by: Fabian Gärtner <fabian.gaertner@check24.de>

Co-authored-by: S@P <lorenzotorracchi@mail.com>
Co-authored-by: Oleg Kovalov <iamolegkovalov@gmail.com>
Co-authored-by: Mike Lloyd <mlloyd@rts.com>
Co-authored-by: Fabianexe <Fabianexe@gmail.com>
Co-authored-by: Fabian Gärtner <fabian.gaertner@check24.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants