Skip to content

Improve performance - #122

Open
gharlan wants to merge 1 commit into
pascaldevink:masterfrom
gharlan:performance
Open

Improve performance#122
gharlan wants to merge 1 commit into
pascaldevink:masterfrom
gharlan:performance

Conversation

@gharlan

@gharlan gharlan commented Jul 6, 2025

Copy link
Copy Markdown
Contributor

ShortUuid::encode can be called quite often when having many urls on a page.

On a random page in my project this pr gives this improvement (measured via blackfire):

Comment thread src/ShortUuid.php
{
$this->alphabet = $alphabet;
$this->alphabetLength = count($alphabet);
$this->alphabetLength = BigInteger::of(count($alphabet));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

brick/math converts this value in all operations into BigInteger objects. Now we are doing it here once, so it does not have to be converted again and again.

Comment thread src/ShortUuid.php
$previousNumber = clone $number;
$number = $number->dividedBy($this->alphabetLength, RoundingMode::DOWN);
$digit = $previousNumber->mod($this->alphabetLength);
[$number, $digit] = $number->quotientAndRemainder($this->alphabetLength);

@gharlan gharlan Jul 6, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

.. but this has the bigger impact on the performance.

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.

1 participant