miantalha45 commented on issue #3460: URL: https://github.com/apache/fory/issues/3460#issuecomment-4266859101
@chaokunyang I traced the Struct Serialize regression (58.60 ns to 106.13 ns) to swift_beginAccess overhead on var storage: [UInt8] in ByteBuffer. For a small all-primitive struct, the current write path triggers 6 separate storage accesses: reserve(), writeInt32() for schema hash, then 4 more inside writeRegion() (count read, append, withUnsafeMutableBufferPointer, removeLast). At ~7-8 ns per access, that adds ~42-48 ns on top of the 58 ns baseline. I propose two fixes. Short-term: fold the schema hash write into the writeRegion block. This eliminates the standalone reserve() and writeInt32() calls, dropping from 6 storage accesses to 4 and recovering roughly 14-16 ns. Long-term: replace var storage: [UInt8] with a raw-pointer-backed store. A private final class holds an UnsafeMutableRawPointer and ByteBuffer holds a let reference to it. Writes through the raw pointer bypass Swift's exclusivity tracking entirely. All existing method signatures stay the same. This fixes the regression across all struct types and all serialization paths. I am willing to implement both. I can send a draft PR if you want to review the direction first. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
