Skip to content

Improve .extend() performance - #112

Merged
bluss merged 2 commits into
masterfrom
extend-improvement
Nov 28, 2018
Merged

Improve .extend() performance#112
bluss merged 2 commits into
masterfrom
extend-improvement

Conversation

@bluss

Copy link
Copy Markdown
Owner

cc #101

I'm experimenting with different formulations. Both the existing and this pr's implementations can compile into a memcpy, like they should, if the input is a cloned slice iterator. The main difficulty seems to be to make a good benchmark. Without "black_box"es, the benchmarks compile out (and that's normally a good sign in itself, the code is then transparent to the optimizer) and with too many black box calls, the optimizations are disabled.

@blussbluss changed the title Improve .extend() performanceImprove .extend() performance (?)Nov 25, 2018
@bluss

Copy link
Copy Markdown
OwnerAuthor

Not entirely happy with these benchmarks either, see code in the PR, but they seem fair(? please review)

 name 63 ns/iter 62 ns/iter diff ns/iter diff % extend_with_constant 294 (1741 MB/s) 1 (512000 MB/s) -293 -99.66% extend_with_range 426 (1201 MB/s) 289 (1771 MB/s) -137 -32.16% extend_with_slice 424 (1207 MB/s) 13 (39384 MB/s) -411 -96.93% extend_with_write 13 (39384 MB/s) 13 (39384 MB/s) 0 0.00%

obviously when extend_with_constant optimizes out it doesn't tell us so much, except that the new extend code is somehow more transparent to the compiler than the old.

@bluss

Copy link
Copy Markdown
OwnerAuthor

Comparison with try_extend_from_slice shows that they both compile to memcpy:

test extend_from_slice ... bench: 14 ns/iter (+/- 1) = 36571 MB/s
test extend_with_slice ... bench: 13 ns/iter (+/- 1) = 39384 MB/s

extend_with_slice is the regular extend() used with a slice iterator (benchmark is in the PR).

@bluss
bluss merged commit ef7ab56 into masterNov 28, 2018
@blussbluss changed the title Improve .extend() performance (?)Improve .extend() performanceNov 28, 2018
@bluss
bluss deleted the extend-improvement branch November 28, 2018 16:01
Sign up for freeto 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.

1 participant

@bluss