-
Notifications
You must be signed in to change notification settings - Fork 58
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
[PR 4/5] Rewrite existing extensions using unsafe API #337
Conversation
0a8eff3
to
94e8786
Compare
1855228
to
0a163a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any performance tests? It seems to me that a slight performance drawdown is inevitable
core/common/src/Buffers.kt
Outdated
@@ -22,7 +22,9 @@ public fun Buffer.snapshot(): ByteString { | |||
var curr = head | |||
do { | |||
check(curr != null) { "Current segment is null" } | |||
append(curr.data, curr.pos, curr.limit) | |||
for (idx in 0 until curr.size) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it not degrading performance?
It seems to me that writing byte-by-byte will be very slow due to the large number of checks and frequent copyInto
calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll reimplement it. We don't track Buffer.snapshot
performance, so it didn't ring the bell once I plunked a naive implementation.
94e8786
to
2f3b57b
Compare
Sure, I'll publish results. |
@shanshin, so, regarding the performance. Of course, adding a level of abstraction over a byte array won't make it faster compared to direct access to the byte array. And that's true for older JDK versions. Here, for instance, benchmarking results collected using JDK11:
tl;dr: on average, everything slowed down and UTF8-processing became 15-50% slower: Summary table for Utf8StringBenchmark
However, more up-to-date runtimes are capable of handling this new level of abstraction, resulting in the same or even better performance compared to what could be achieved with the code from the master branch.
tl;dr: a few benchmarks show some slowdown, but in general, performance either improved or remained at the same level. Summary table for Utf8StringBenchmark
On the Android, results are somewhat similar.
Summary table for Utf8StringBenchmark
However, when R8 kicks in, results start looking similar to what was observed with recent JDK versions:
Summary table for Utf8StringBenchmark
To summarize: it's definitely hard to beat a code reading/writing directory to/from a byte array by wrapping these accesses into interface calls. But modern optimizing compiler are good at it and allow preserving the same performance level. |
@fzhinkin what about the perf impact for non-JVM platforms, like Native, or they aren't impacted at all? |
@lppedd, on Native, marginally, there's a small slowdown when it comes to UTF8 processing, but overall, things look good:
|
@fzhinkin thanks! Do you save previous benchmark results somewhere? |
@lppedd, no, I don't, but it's worth saving. Thanks for the suggestion! |
23aaaab
to
0a86a46
Compare
This PR reimplements existing extensions to use unsafe API introduced in #334 and #336.
In the next patch, Segment's
data
field will be encapsulated.Related to #135