Skip to content

[Uid] Add microsecond precision to UUIDv7 and optimize on x64 #60898

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
Jun 27, 2025

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Issues -
License MIT

This makes our implementation of UUIDv7 follow method 3 described by the RFC:
https://www.rfc-editor.org/rfc/rfc9562#section-6.2-5.6.1

UUIDv7 will now contain microsecond timestamp instead of just milliseconds.
This allows optimizing the code a bit, and I further optimized the x64 code path.
This makes the generation logic about 10% faster.

Copy link
Member

@alexandre-daubois alexandre-daubois left a comment

Choose a reason for hiding this comment

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

Works nicely! Could we have a test covering that UUIDv7 microseconds is actually stored on generation? Something like:

public function testV7MicrosecondPrecision()
{
    $testCases = [
        '1645557742.000001',
        '1645557742.123456', 
        '1645557742.999999'
    ];
    
    foreach ($testCases as $timeStr) {
        $timestamp = \DateTimeImmutable::createFromFormat('U.u', $timeStr);
        $uuidStr = UuidV7::generate($timestamp);
        $uuid = UuidV7::fromString($uuidStr);
        
        $expected = $timestamp->format('U.u');
        $actual = $uuid->getDateTime()->format('U.u');
        
        $this->assertSame($expected, $actual);
    }
}

@nicolas-grekas
Copy link
Member Author

Thanks for the proposal, PR updated with a test case inspired from yours.

@nicolas-grekas nicolas-grekas merged commit fa8b32e into symfony:7.4 Jun 27, 2025
3 of 11 checks passed
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.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy