-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KT-72492: Optimize String.toFloatOrNull()
The existing implementation used a regular expression which caused memory allocations, which are expensive on mobile devices. In addition, a custom parser can outperform regular expressions. The new implementation is compatible with the original regular expression and performs ~22x faster on OpenJDK 22 with a 2021 MacBook Pro M1 Pro: Benchmark Mode Cnt Score Error Units KotlinBenchmark.customParser thrpt 482.020 ops/ms KotlinBenchmark.regex thrpt 21.471 ops/ms On a Pixel 6 running Android 14, the new implementation is ~225x faster: 8,595,686 ns 10428 allocs Trace ColorBenchmark.isFloatRegex 37,755 ns 0 allocs Trace ColorBenchmark.isFloat It also has the benefit of never allocating anything (vs ~940 allocations per invocation for the existing implementation). ^KT-72492 Co-authored-by: Romain Guy <[email protected]> Co-authored-by: Jake Wharton <[email protected]> Co-authored-by: Filipp Zhinkin <[email protected]> Merge-request: KT-MR-18243 Merged-by: Filipp Zhinkin <[email protected]>
- Loading branch information
1 parent
79165c7
commit 3675473
Showing
2 changed files
with
472 additions
and
25 deletions.
There are no files selected for viewing
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
Oops, something went wrong.