swift 6.0+ performance tweaks 3x-6x #9067
swift 6.0+ performance tweaks 3x-6x #9067blindspotbounty wants to merge 4 commits intogoogle:masterfrom
Conversation
|
1- is there any chance that you also add or investigate the same changes to the flexbuffer implementation? |
|
Sorry for extra ping, I was a bit trigger happy there - missed you were in @mustiikhalil - will let @blindspotbounty respond. |
When do you think it will go in approx? Looks like a great update, 5.10 and older is more or less gone now I think. |
Not sure, I pinged for help to review it let's see though! If it doesn't get reviewed the today or tomorrow then we can merge this and update the other branch |
mustiikhalil
left a comment
There was a problem hiding this comment.
Amazing work! some minor changes! and ofc the CI hasnt passed
| @usableFromInline | ||
| var serializeDefaults: Bool |
There was a problem hiding this comment.
I wonder, can this simply be a let
| case .data(let data): | ||
| self = .data(data) | ||
| case .bytes(let contiguousBytes): | ||
| self = .bytes(contiguousBytes) |
There was a problem hiding this comment.
requires OS not wasm flag
| #if compiler(>=6.0) | ||
| @inline(__always) | ||
| init( | ||
| blob: borrowing Storage.Blob, | ||
| count: Int, | ||
| removing removeBytes: Int) | ||
| { | ||
| _storage = Storage(blob: blob, capacity: count) | ||
| _readerIndex = removeBytes | ||
| capacity = count | ||
| } | ||
| #else |
There was a problem hiding this comment.
Im wondering if we can reduce the amount of #if compiler specially for language features that are available in 5.10, example: borrowing
There was a problem hiding this comment.
I think I can wait for #8983 and remove all swift>=6.0 annotations all together.
|
@blindspotbounty The swift upgrade PR has been merged! Please pull, and update the current Pr with the changes required. We will need to check if the gRPC changes will run with the new code change that you've done. Then it would be interesting to look at the changes for flexbuffers (I use those more than flatbuffers nowadays) |
We were experimenting with the latest changes for swift flatbuffers runtime and found several tweaks that allow to have significantly faster:
letBlobas@frozenfor library evolution modeBlobas~Copyableto avoid compiler inserted copies (swift 6.0+)BitwiseCopyableannotation for directly read types (swift 6.0+)exclusivity(unchecked)for FlatbuffersBuilder - assuming it is always exclusive anywayfunc duplicateto not crash in debug with default valueBenchmarks give a lot of false negative/positive results in main vs main on my machine (i.e. deviation is >+-5%). I guess mainly due to allocations.
However, there are the main improvements:
For serialization I probably need to add one more test. However the difference is quite noticeable.
Was:

Became:

All improvements are manly due to removing swift runtime calls: exclusivity checks and runtime metadata access.
In practice, all improvements give up to 3x-6x gain on scale.
@mustiikhalil I put all tweaks that we have currently together.
Let me know if I should split them or if something is going to be implemented other way (or if I need to make separate cases for those improvements).