Skip to content

Conversation

marc-mabe
Copy link
Contributor

@marc-mabe marc-mabe commented Jul 27, 2025

Currently uniqid waits until the current microsecond has been changed until the previous call.

This PR changes this logic instead of waiting until the current microsecond changes, it simply increments in case the current time is <= the previous.

This makes uniqid unaffected by time changes (like ntp) and also it's faster (if called very often) due to less system calls.

A simple benchmark:
BEFORE: 100911477ns
AFTER: 57341969ns

uniqid(); // warmup

$start = hrtime(true);
for ($i = 0; $i < 100000; ++$i) {
        uniqid();
}
echo (hrtime(true) - $start) . "ns\n";

@TimWolla
Copy link
Member

This effectively is a duplicate of #18232.

@marc-mabe
Copy link
Contributor Author

This effectively is a duplicate of #18232.

OMG, I wasn't aware there is already another PR addressing the same.
Also, if this requires an RFC I'll not continue on that as this function should be avoided anyway.

@marc-mabe marc-mabe closed this Jul 27, 2025
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.

2 participants