[2.x] perf: skip mime detection in JsDirectoryCompiler when extension matches - #4632
Merged
Merged
Conversation
eachFile() called Filesystem::mimeType() for every file in every per-extension JS bundle directory, on every request — finfo_file is ~1ms per call, and a typical install with ~40 extensions paid 60-80ms of TTFB to it on every page. The mime check was only ever a fallback for cases where the .js extension check failed (e.g. minified bundles served without the extension). Short-circuit when the cheap extension check has already matched. Behavior is identical: every file processed before is processed, every file skipped is still skipped. Only timing changes. Fixes #4616
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
JsDirectoryCompiler::eachFile()calledFilesystem::mimeType()for every file in every per-extension JS bundle directory, on every request —finfo_file()is ~1ms per call, and a typical install with ~40 extensions paid 60–80ms of TTFB to this single loop on every page.The mime check was only ever intended as a fallback for cases where the
.jsextension check fails (e.g. minified bundles served without the extension, see #4329). Short-circuit when the cheap extension check has already matched.Behavior is identical: every file processed before is still processed, every file skipped is still skipped. Only timing changes.
Fixes #4616
Changes
framework/core/src/Frontend/Compiler/JsDirectoryCompiler.php— only call$filesystem->mimeType()when$hasJsExtensionis false.Reporter's verified improvement (production install, 10-sample TTFB medians)
/u/<user>/(forum index, ~50 discussions)/d/<id>(small discussion)Test plan
php flarum cache:clearandphp flarum assets:publish, confirm bundles still compile and serve..jsextensions (the original case [2.x] fix: identify minified js reliably #4329 was added to handle), verify they're still picked up — the mime fallback is unchanged for those, only its timing is gated.The patch is the same one the reporter verified live in production for 24h with no regressions.