Skip to content
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

[2.x] Replace md5 with xxhash #653

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from

Conversation

RobertBoes
Copy link
Contributor

Another attempt of #652

I recently noticed laravel/framework#52301, where most of the md5 calls will be replaced with xxhash, which is much faster than md5. For Inertia's asset versioning we don't need it to be cryptographically correct, but a performance improvement would be nice, especially since the middleware is executed on every request.

I think it's save to change this in the Inertia adapter, since all it would do is force a reload, which would happen when updating assets anyway.

Support for xxhash was added to PHP 8.1 (https://php.watch/versions/8.1/xxHash), so we can safely use this algorithm instead of md5.

@RobertBoes
Copy link
Contributor Author

Did a bit of testing in an artisan command, especially the md5_file call is quite a bit slower;

Benchmark::dd([
    'md5' => fn() => md5_file(public_path('build/manifest.json')), // around 0.085ms
    'xxhash' => fn() => hash_file('xxh128', public_path('build/manifest.json')), // around 0.040ms
], 1000);

Of course it's not a massive impact, but it's a free improvement

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