perf: optimize Swift SDK with async API, mmap loading, and hex lookup table - #17
Open
Bisht13 wants to merge 6 commits into
Open
perf: optimize Swift SDK with async API, mmap loading, and hex lookup table#17Bisht13 wants to merge 6 commits into
Bisht13 wants to merge 6 commits into
Conversation
Static table of 256 hex strings indexed by byte value. 10-50x faster than invoking NSString format parser per byte for large proofs.
Wraps sync methods via withCheckedThrowingContinuation + DispatchQueue so prove() (100ms-10s) does not block the calling thread.
Same pattern as ProverScheme — wraps sync methods via withCheckedThrowingContinuation + DispatchQueue.
Async variants for all load, prove, and verify operations. Dispatches FFI work to background queue so callers are never blocked.
New loadProver(mappedFrom:) and loadVerifier(mappedFrom:) methods use POSIX mmap() instead of heap allocation for file contents. The OS pages in data on demand and reclaims under memory pressure — better for large schemes on memory-constrained iOS devices. Sync and async variants.
Covers async prove/verify roundtrip, mmap load + prove/verify, async mmap load, and mmap error handling for nonexistent files.
Bisht13
force-pushed
the
feat/swift-sdk-optimization-clean
branch
from
April 9, 2026 02:31
78cb8c5 to
cf72b06
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
withCheckedThrowingContinuation, preventing UI freezes on iOS when proving takes 100ms-10smmap()— newloadProver(mappedFrom:)/loadVerifier(mappedFrom:)methods avoid heap allocation for multi-MB scheme files on memory-constrained devicesString(format:"%02x")with a static 256-entry table, 10-50x faster for hex display of large proofsDetails
All changes are additive and non-breaking — existing sync methods are unchanged. Async variants wrap sync methods, inheriting their lock-based thread safety. The mmap implementation has proper POSIX resource cleanup (
defer close(fd)after open,defer munmapafter mmap, zero-length file guard).Concurrency model: Async methods move work off the main thread but do NOT enable concurrent operations on the same handle (Barretenberg backend is not safe for same-handle concurrency). For parallel proving, create multiple
ProverSchemeinstances.Files changed: 6 files, +362 lines (all in
sdks/swift/)Test plan
make test-swiftto verify integration tests (async roundtrip, mmap roundtrip, mmap error case)