Skip to content

[Uid] Optimize UuidV4 generation #53963

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

Merged
merged 1 commit into from
Feb 20, 2024
Merged

Conversation

smnandre
Copy link
Member

Q A
Branch? 7.1
Bug fix? no
New feature? no
Deprecations? no
Issues Fix #
License MIT

I tried to optimize as much as I could the UuidV4 generation.

According to local tests, the code is now between 35% and 40% faster.

(But to be fair... we are talking nanoseconds here 😅)

Thanks @nicolas-grekas for the help in this useless fun quest 😃

--

--> Bench (& results): https://github.com/smnandre/uuid-bench

@lyrixx
Copy link
Member

lyrixx commented Feb 16, 2024

I would be nice to add more comments in the code to explain the code

@smnandre
Copy link
Member Author

@lyrixx
I added comments to explain step by step what's done. Tell me if you see anything incorrect there :)

@smnandre smnandre mentioned this pull request Feb 16, 2024
fabpot added a commit that referenced this pull request Feb 20, 2024
This PR was squashed before being merged into the 7.1 branch.

Discussion
----------

[Uid] Minor updates

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #
| License       | MIT

Some minor things i found while [playing with UuidV4](#53963).

In those places, calling the polyfill cost us a lot of operations, as we already did most of the checks, might as well running directly the expected code.

Full disclosure: at first, i wanted to remove entirely the uuid_ pecl / polyfill dependencies. But uuid_create is still used for UuidV1 / V7 generation, and more perorfmant than the polyfill.

After this PR, the extension (or the polyfills) are still used via 2 methods: `uuid_create` and `uuid_compare`.

Commits
-------

a2e5dca [Uid] Minor updates
@fabpot fabpot force-pushed the feat/optimize-uuidv4 branch from fdff529 to 7b5c57b Compare February 20, 2024 16:29
@fabpot
Copy link
Member

fabpot commented Feb 20, 2024

Thank you @smnandre.

@fabpot fabpot merged commit 86b07f0 into symfony:7.1 Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants