-
Notifications
You must be signed in to change notification settings - Fork 8
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
Follow up question about interfacing with the client from the service #5
Comments
I'm also curious how long it takes if you encode the output from |
Hi Charles,
I tried encoding/decoding the data from
Thanks for taking the time to look into this. I would really prefer to keep using your package over the vanilla XPC, but this is such an important bottleneck that it would be impossible right now. |
Hi Steve, The trouble with using I get similar results to you with import SwiftyXPC
import Cocoa
func measure(_ name: String, closure: () -> Void) {
let startTime = Date()
closure()
print("\(name) took: \(Date().timeIntervalSince(startTime))")
}
let bitmap = NSBitmapImageRep(
bitmapDataPlanes: nil,
pixelsWide: 2000,
pixelsHigh: 2000,
bitsPerSample: 8,
samplesPerPixel: 1,
hasAlpha: false,
isPlanar: false,
colorSpaceName: .deviceWhite,
bytesPerRow: 0,
bitsPerPixel: 0
)!
let encoder = XPCEncoder()
let decoder = XPCDecoder()
let data = bitmap.tiffRepresentation
measure("encoding and decoding") {
let encoded = try! encoder.encode(data)
let decoded = try! decoder.decode(type: Data.self, from: encoded)
withExtendedLifetime(decoded) {} // to silence some warnings
} Running this in both debug and release mode, I get: $ swift build; .build/debug/perftest
Building for debugging...
Build complete! (0.20s)
encoding and decoding took: 0.4505230188369751
$ swift build -c release; .build/release/perftest
Building for production...
Build complete! (0.20s)
encoding and decoding took: 0.0896080732345581 You can see the difference that release mode makes. We can break it down by encode and decode: var encoded: xpc_object_t!
measure("encoding") {
encoded = try! encoder.encode(data)
}
measure("decoding") {
let decoded = try! decoder.decode(type: Data.self, from: encoded)
withExtendedLifetime(decoded) {}
} This gets us: $ swift build -c release; .build/release/perftest
Building for production...
Build complete! (0.08s)
encoding took: 0.03677201271057129
decoding took: 0.053681015968322754 That's still a bit slower than vanilla XPC; profiling reveals that the reason is that since Fortunately, For the time being, I've pushed up a fix using the new runtime parametrized protocols in Swift 5.7 (taking advantage of the fact that $ swift build -c release; .build/release/perftest
Building for production...
Build complete! (0.22s)
encoding took: 0.0009380578994750977
decoding took: 0.0003399848937988281 Let me know what you think. |
Thanks so much for your previous answer and example code, it helped me a ton and I now have a good prototype for the service I'm aiming for.
I have run however into a major issue.
Here's the setup. My service needs to send some data to the client really fast. I do this using the
sendOnewayMessage
method on theXPCConnection
created from anXPCEndpoint
. The message that is sent is a struct conforming toCodable
with a single property of typeNSBitmapImageRep
.In a Unit test, I have used a 2000 x 2000 8 bits bitmap (4 MB) to measure the performance of those 2 blocks of code:
This runs with a Time: 0.006 sec
And this runs with a Time: 0.467 sec
In the end, I'm not sure what my question is, but maybe you could enlighten me on what is going on in both the Decoder and the Encoder and why they are this slow.
The text was updated successfully, but these errors were encountered: