perf: eliminate hot-path filesystem and regex costs in handler/routing layer#665
Merged
Merged
Conversation
…g layer
Four targeted optimizations on the per-request execution path:
1. HandlerService: cache ImplicitViews setting
`getSetting("ImplicitViews")` was called on every handler dispatch where
the requested action was missing. It is now cached to variables scope in
onConfigurationLoad() alongside every other already-cached setting.
2. HandlerService.isViewDispatch: drop redundant fileExists(expandPath())
locateView/locateModuleView already verify file existence and return the
path with a .cfm/.bxm extension only when the file is confirmed present.
The follow-up fileExists() call was re-doing answered work. Replaced with
a cheap string suffix check — zero filesystem I/O.
3. RoutingService.findRoute: use cached canDebug local variable consistently
canDebug was already stored in a local variable at the top of findRoute()
but three spots inside the same method re-called getLogger().canDebug()
instead of using it. All three now use the cached local variable.
4. Router/RoutingService: pre-parse response string placeholders at registration
renderResponse() was running reMatchNoCase + reReplaceNoCase on the route's
static response string on every request. Tokens are now parsed once in
addRoute() into a responsePlaceholders array; renderResponse() iterates the
pre-parsed list with no regex at runtime. Also fixes a latent bug where
multiple placeholders were not all applied (original always replaced into
the original string rather than the accumulated result).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MUinjJLvJod1u9s2e9T6zc
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MUinjJLvJod1u9s2e9T6zc
… for $getProperty - Router.addRoute() builds thisRoute from arguments struct, not initRouteDefinition(), so responsePlaceholders was only added for string responses. Add else branch to set [] for closure/empty cases. - HandlerServiceTest: getHandlerService() returns the real service object; call prepareMock() before using $getProperty to access variables scope. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MUinjJLvJod1u9s2e9T6zc
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
Follow-up to the Renderer discovery caching PR. This pass eliminates four confirmed hot-path costs in
HandlerService,RoutingService, andRouter— all on the per-request critical path with no API surface changes.Issue 1 — HandlerService: cache
ImplicitViewssetting (high impact)onConfigurationLoad()already caches every framework setting intovariables.*but was missingImplicitViews. ThegetHandler()method was callingcontroller.getSetting("ImplicitViews")on every handler dispatch where the action does not exist in the handler CFC.Fix: Add
variables.implicitViews = variables.controller.getSetting("ImplicitViews")toonConfigurationLoad()and replace the per-request call ingetHandler().Issue 2 — HandlerService: eliminate redundant
fileExists(expandPath())inisViewDispatch()(high impact)isViewDispatch()was callingfileExists(expandPath(targetView))afterlocateView()/locateModuleView()had already verified file existence. Those methods encode existence in their return value: a path with a.cfm/.bxmextension means the file was found; a bare name without extension means not found.Fix: Replace the filesystem call with an extension check — zero I/O:
This also fixes a latent bug where
locateModuleView()appends.bxmfor BoxLang views but the old code only checked for.cfm.Issue 3 — RoutingService: use cached
canDebuginfindRoute()(medium impact)findRoute()cachedgetLogger().canDebug()into a localcanDebugvariable at the top of the method, but two downstream branches re-calledgetLogger().canDebug()(andgetLogger()) instead of using the already-cached value.Fix: Replace both stray
getLogger().canDebug()calls withcanDebug.Issue 4 — Router/RoutingService: pre-parse route response placeholders at registration (medium impact)
renderResponse()ranreMatchNoCase("{[^{]+?}", aRoute.response)andreReplaceNoCase(...)on every request for routes with a stringresponsevalue. Route definitions are immutable after registration, so the placeholder list never changes.Fix (two-part):
addRoute()— pre-parse{token}placeholders intoroute.responsePlaceholders = [{token, key}, ...]at registration time.renderResponse()— iterate the pre-parsed list; no regex at render time.This also fixes a latent bug in the original loop where each iteration replaced in
aRoute.responserather than the accumulatedtheResponse, so only the last placeholder's substitution survived when a response contained multiple tokens.Test Coverage
HandlerServiceTest.cfc— 3 new specs in a"Hot-path caching optimizations"describe block:variables.implicitViewsis a boolean cached afteronConfigurationLoad()isViewDispatchreturnstruefor a view detected by extensionisViewDispatchreturnsfalsefor a non-existent viewRouterTest.cfc— 5 new specs in a"Response placeholder pre-parsing"describe block:responseproduces emptyresponsePlaceholdersresponseproduces emptyresponsePlaceholdersFiles Changed
system/web/services/HandlerService.cfcsystem/web/services/RoutingService.cfcsystem/web/routing/Router.cfctests/specs/web/services/HandlerServiceTest.cfctests/specs/web/routing/RouterTest.cfcGenerated by Claude Code