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
[SR-10346] excessive reference counting, leading to CoW copy for every heap insert in NIO :| #52746
Comments
Also, turns out there's a nice Swift 5.0 regression in there as well:
now the whole thing should pretty much not allocate at all, but Swift 4.2 does 10k allocs and Swift 5.0 does 20k allocs, not cool 😉 |
so, I could pin-point the Swift 5 regression a little more: If we remove all the generics from the above program and make it
and then run it, then Swift 4.2 and Swift 5.0 perform pretty much the same:
|
CC @eeckstein/@gottesmm |
the great news is that it's fixed with the dev-snapshot from 7th April 2019:
|
I suspect this is because arguments are evaluated left-to-right, and so it needs to save the old value of |
Just to fill in a bit of context: I am not surprised that on master this is not happening anymore since I enabled semantic arc by default. |
I can confirm that the original repro on the actual NIO repository is also fixed in current master. While this specific repro scenario is fixed by semantic ARC (semantic ARC FTW, this issue by itself justifies the work done on it), it may be nice to investigate whether the compiler could have avoided this issue even without semantic ARC, rather than relying on it. Totally up to @belkadan though, I'm certainly not going to make you folks do work you don't feel you need to! |
Not me, I'm deferring to those with more SIL expertise, like Michael, Erik, and Andy. |
Whomever is making the decision, I’m sure that we can all agree that it isn’t me, and be glad of that fact. |
Out of curiosity I grabbed the NIOHTTP2 load tester and ran it with the most recent snapshot (e.g. with semantic ARC). We saw a 10% performance boost with zero code changes on our end, which I'm calling a big win. Looking forward to seeing it land in a productised release! |
@swift-ci create |
I talked with Johannes. He agreed that since this is solved by semantic arc, we can close this. |
Attachment: Download
Additional Detail from JIRA
md5: c52a6805e968aded3891a4cd5ceb1cf7
relates to:
Issue Description:
@Lukasa & I were just debugging weird allocations in NIO's slightly odd heap allocation. Here what we could reduce it to:
The following code (two modules):
main module
OtherModule
should almost not allocate at all. However it allocates twice per loop iteration. It seems to CoW-copy the underlying array twice per iteration.
oddly enough, if you change this line
to
it's just fine and it doesn't allocate & cow-copy anymore. The attached screenshot shows the only bit of diff in the SIL between GOOD and BAD.
repro
Unpack the attached tarball and run
other info
the relevant SIL
Foo.append
Foo.realAppend
so the problem is that BAD does an extra, unnecessary retain/release on
BridgeObject
The text was updated successfully, but these errors were encountered: