Skip to content

Avoid uniqid() for performance sake #9905

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

manu0401
Copy link
Contributor

uniqid() provides time-based unique idenfitiers. In order to avoid collisions, it waits for time to elapse. Depending on PHP version, this is done by sleeping or by polling the gettimeofday() system call, both approach being rather inefficient. uniqid() may take a few dozen of milliseconds to return, and it is called very often to build a page.

AVideo implements _uniqid() which provides random-based unique identifiers. This change replace uniqid() calls by _uniqid() to improve performances.

uniqid() provides time-based unique idenfitiers. In order to avoid
collisions, it waits for time to elapse. Depending on PHP version,
this is done by sleeping or by polling the gettimeofday() system
call, both approach being rather inefficient. uniqid() may take
a few dozen of milliseconds to return, and it is called very often
to build a page.

AVideo implements _uniqid() which provides random-based unique
identifiers. This change replace uniqid() calls by _uniqid()
to improve performances.
@DanielnetoDotCom
Copy link
Member

Sorry but I do not like this find and replace without test

also I am not sure if it will make any difference in the performance.

Currently you are the only one complaining that slow down on last update

also does it already makes any difference for you? how much performance did you gain?

@manu0401
Copy link
Contributor Author

manu0401 commented Feb 28, 2025 via email

(that means: PHP native uniqid() is used unless the setting is toggled)

_uniqid() also gets an optional parameter to force the local implementation
instead of native PHP uniqid(), whatever the global setting is.
as we may have been included from a plugin.
Copy link

stale bot commented Apr 26, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 26, 2025
@manu0401
Copy link
Contributor Author

manu0401 commented Apr 26, 2025 via email

@stale stale bot removed the wontfix label Apr 26, 2025
@manu0401 manu0401 mentioned this pull request Apr 26, 2025
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