-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: improve byte to hex string conversion optimizations (#701)
* Improve hex string to DataView conversion performance in TypeScript Benchmarks can be found at https://www.measurethat.net/Benchmarks/Show/32317/0/parse-hex-to-bytes---test-capacitor-bluetooth-le-conver Performance improvement is platform dependent but appears to be about 9x faster on iOS and Android * Improve DataView to hex string conversion in Kotlin In the future the Kotlin Stdlib may support this conversion, but it is currently marked as experimental. This implementation is less configurable but perhaps a bit faster. Passing about 512KB of data through a notification characteristic with the old method utilized about 21.5 seconds of wall clock time. This implementation utilized 124.61 milliseconds, a whopping 172X speedup. When using a notification characteristic to transfer binary data to the central over BLE, this speedup is very noticeable. * Improve Data to Hex String Conversion in Swift Unfortunately, I don't have a Mac to build an iOS test case, so I ran some toy benchmarking on my PC using the Swift 6.0.1 toolchain for Windows. I ran 1000 iterations of converting a 4KB Data blob to a hex string using the existing algorithm, which took 25.14 seconds to finish. Running the same test with this proposed implementation took 0.91 seconds, yielding a speedup of "only" ~27x. While this isn't as significant as the Kotlin optimization, this is my first time writing any Swift code, so there may be additional performance improvements to explore. On that front, I would appreciate scrutiny (and testing, if possible!) from iOS developers. I ran some test cases on Windows, and everything looked fine. * Swift: Provide a fallback path for iOS < 14 Benchmarking this implementation on my PC shows that it runs at about half the speed of the fast path but is still substantially faster than the existing implementation: iOS14+Conv: Time taken for 1000 iterations with data size 4096 bytes: 0.8684617 seconds FallbackConv: Time taken for 1000 iterations with data size 4096 bytes: 1.3471951 seconds BaselineConv: Time taken for 1000 iterations with data size 4096 bytes: 23.8809594 seconds
- Loading branch information
1 parent
83e2b1b
commit e064587
Showing
6 changed files
with
88 additions
and
25 deletions.
There are no files selected for viewing
27 changes: 21 additions & 6 deletions
27
android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/Conversion.kt
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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