-
Notifications
You must be signed in to change notification settings - Fork 638
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
ByteBuffer: provide multi read/write int methods #1987
Conversation
|
@swift-nio-bot perf test this please |
|
@Lukasa we should probably make this |
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.
Left a couple of nits but otherwise looks good and I think this is a useful change, thanks jw!
|
@swift-nio-bot test perf please |
|
@swift-nio-bot test perf please |
performance reportbuild id: 83 timestamp: Fri Nov 19 11:01:40 UTC 2021 results
comparison
significant differences found |
performance reportbuild id: 84 timestamp: Fri Nov 19 11:04:53 UTC 2021 results
comparison
significant differences found |
|
Nice, this will unlock some nice perf gains in postgres :) |
bb5d09a
to
5a5c76d
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.
LGTM except for a minor nit around the asserts.
Motivation: Many network protocols (especially for example NFS) have quite a number of integer values next to each other. In NIO, you'd normally parse/write them with multiple read/writeInteger calls. Unfortunately, that's a bit wasteful because we're checking the bounds as well as the CoW state every time. Modifications: - Provide read/writeMultipleIntegers for up to 15 FixedWidthIntegers. - Benchmarks Result: Faster code. For 10 UInt32s, this is a 5x performance win on my machine, see benchmarks.
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.
LGTM. A good example for what we might use TypeSequences aka Variadic Generics if we get the same performance out of it. Maybe worth posting this use case on the pitch thread.
We could, however the variadics would only really if the types are all the same. Ie |
|
@weissi Not sure I can follow you here, the pitch for TypeSequences contains this code example: func debugPrint<T...>(_ items: T...)
where T: CustomDebugStringConvertible
{
for (item: T) in items {
stdout.write(item.debugDescription)
}
}If I read this correctly, the new script generated code could be implemented as this, couldn't it? func readMultipleIntegers<T...>(endianness: Endianness = .big, as types: T.Type...)
where T: FixedWidthInteger
{
// implementation
} |
Thank you! yes, I missed the ellipsis in the generic arguments. That's cool if this would be supported, very nice! |


Motivation:
Many network protocols (especially for example NFS) have quite a number
of integer values next to each other. In NIO, you'd normally parse/write
them with multiple read/writeInteger calls.
Unfortunately, that's a bit wasteful because we're checking the bounds
as well as the CoW state every time.
Modifications:
Result:
Faster code. For 10 UInt32s, this is a 5x performance win on my machine,
see benchmarks.