Skip to content
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

Improve [U]Int128 string conversion performance. #65508

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

mgriebling
Copy link

@mgriebling mgriebling commented Apr 28, 2023

String to [U]Int128 conversions are 9 times faster.
[U]Int128 to String conversions are 25 times faster.

@stephentyrone suggested my [U]Int128 changes would be better placed in the standard library.
[U]Int128 probably fits better in the standard library itself (there's already a partial implementation there to support Duration.

private static func times<T:FixedWidthInteger>(
x: T, timesRadix radix: UInt64, toPower n: Int) -> T {
// calculate the powers of the radix and store in a table
if powers.isEmpty || powers.first! != radix {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has an obvious toctou race condition, as well as a more subtle race condition on targets without total store ordering. I don't think that it's actually possible to use a lazily computed table of powers like this without an explicit lock. Given what the expected distribution of radices looks like, simply covering power-of-two bases with a precomputed table for base 10 would be a much more attractive solution.

Copy link
Author

@mgriebling mgriebling Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! Will do a precomputed table for base 10 and powers of 2.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephentyrone, latest update should fix this race condition issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants