-
Notifications
You must be signed in to change notification settings - Fork 634
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
Improve the performance of copying CircularBuffer #2059
Improve the performance of copying CircularBuffer #2059
Conversation
Signed-off-by: Si Beaumont <beaumont@apple.com>
@swift-nio-bot test perf please |
performance reportbuild id: 108 timestamp: Mon Mar 7 18:13:04 UTC 2022 results
comparison
significant differences found |
Nice, that's a solid win of about 20%! |
Sources/NIOCore/CircularBuffer.swift
Outdated
return (self.makeIterator(), buffer.startIndex) | ||
} | ||
|
||
let indexRanges: [Range<Int>] |
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.
Hmm, we need to confirm that this doesn't allocate, but I forgot to get you to set limits. One sec.
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.
@Lukasa Thanks for the review. Should I run the alloc tests locally or wait for the CI to do it's thang?
@simonjbeaumont Looks like Swift was not able to optimise the Array you allocated in the implementation. As we will only ever store one or two ranges, can I propose using some |
Signed-off-by: Si Beaumont <beaumont@apple.com>
Signed-off-by: Si Beaumont <beaumont@apple.com>
Signed-off-by: Si Beaumont <beaumont@apple.com>
Signed-off-by: Si Beaumont <beaumont@apple.com>
@swift-nio-bot test perf please |
performance reportbuild id: 109 timestamp: Tue Mar 8 14:24:37 UTC 2022 results
comparison
significant differences found |
Hm... this seems to have made things worse... I mean, it's still better for this test than |
The regressions were there in the other benchmarks. I suspect that many of these benchmarks are not running often enough so they're below the noise floor. |
So where does that leave us. Do we have any confidence that this PR is moving things in the right direction, or do we think it's all noise? |
I think there are two options here, but the best one is to probably make a PR that raises the runtime of these various benchmarks to around the hundreds-of-ms runtime. That is a larger runtime that makes it a bit easier for us to observe the performance changes. Is that something you have the bandwidth to do? If not I can try to get to it. |
@swift-nio-bot test perf please |
performance reportbuild id: 129 timestamp: Thu Mar 24 15:30:20 UTC 2022 results
comparison
significant differences found |
OK, so now we've merged #2063 we have lost the noise which made it look like this PR made things worse. It's mostly stable for things that it shouldn't affect and up to ~10% faster for some benchmarks. The only wrinkle is Looks like for 5.2 there was a single rogue allocation which tripped things:
@Lukasa unrelated? |
Unrelated I suspect, that number has been a bit aggressively low for a while. Let's just re-run, it should pass. |
@swift-nio-bot test this please |
1 similar comment
@swift-nio-bot test this please |
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.
In general this looks good to me. We could get this to go a little faster by dropping down to raw pointers ourselves and using unsafeBitcasts and things, but I don't think it's really worth it.
Motivation:
#1827 suggests we implement some hooks on Collection and Sequence to get better performance for CircularBuffer to increase performance. #2058 added the benchmarks so we can see the improvement from this change.
Modifications:
Implement
Sequence._copyContents
forCircularBuffer
in terms of its underlyingContiguousArray
to avoid going through the extra layer of indices.Result:
Copying
CircularBuffer
should be faster.