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

Use an optimal way to get the UTF8 length #1369

Merged
merged 1 commit into from Nov 28, 2018

Conversation

Projects
None yet
3 participants
@pushkarnk
Copy link
Contributor

pushkarnk commented Nov 16, 2018

We currently use NSString.lengthOfBytes(using:) to calculate the length of the UTF8 bytes. A flamegraph analysis of Kitura against a simple HelloWorld benchmark proves this to be sub-optimal. Using the String.utf8.count instead bumps up performance by 12-14%.

Use an optimal way to get the UTF8 length
We currently use NSString.lengthOfBytes(using:) to calculate the length of the UTF8 bytes. A flamegraph analysis of Kitura against a simple HelloWorld benchmark proves this to be sub-optimal. Using the `String.utf8.count` instead bumps up performance by 12-14%.

@ianpartridge ianpartridge requested a review from djones6 Nov 21, 2018

@djones6
Copy link
Member

djones6 left a comment

It is indeed faster... although I only measured around 3% (with Kitura-net on Linux).

I was disappointed that replacing all this with send(data: str.data(using: .utf8)!) wasn't any faster. I suspect that it will be once the Swift 5 utf8 changes land (assuming the perf improvements arrive in Swift 5).

@pushkarnk pushkarnk merged commit a998fc4 into IBM-Swift:master Nov 28, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
license/cla Contributor License Agreement is signed.
Details

@djones6 djones6 referenced this pull request Jan 16, 2019

Merged

Faster way to calculate utf8Length #286

1 of 3 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment