You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current implementation of the HTTP router suffers from redundancy and inefficiencies, particularly in route handling. Routes with the same path but different HTTP methods or handlers lead to duplicated route definitions, increased memory consumption, and slower lookup times.
To address these issues, I propose optimizing the HTTP router by consolidating routes with the same path into single route objects and internally mapping HTTP methods to their corresponding handlers. This approach reduces memory usage, streamlines route matching, and simplifies the codebase. By leveraging maps for method-handler associations, we achieve faster lookup times and improved runtime performance.
Implementation Details:
Route Consolidation: Routes with the same path will be consolidated into single route objects.
Method-Handler Mapping: Internally within each route object, HTTP methods will be mapped to their corresponding handlers using a map data structure.
Route Matching Refinement: The route matching logic will be simplified to focus solely on comparing the request's path to the route's path. Once a matching route is found, the appropriate handler based on the request's HTTP method will be retrieved from the route's internal map (405 in case HTTP-Method is not supported).
Code Refactoring: The codebase will be refactored to encapsulate method-handler associations within route objects, promoting better code organization and maintainability.
P.S This is my first-ever issue/proposal so feel free to correct and educate me in case I am wrong or missing something!
P.S.S @alexedwards In case this proposal seems reasonable I will be more than happy to create a PR :)
The text was updated successfully, but these errors were encountered:
Problem:
The current implementation of the HTTP router suffers from redundancy and inefficiencies, particularly in route handling. Routes with the same path but different HTTP methods or handlers lead to duplicated route definitions, increased memory consumption, and slower lookup times.
Example:
Output:
Proposed Solution:
To address these issues, I propose optimizing the HTTP router by consolidating routes with the same path into single route objects and internally mapping HTTP methods to their corresponding handlers. This approach reduces memory usage, streamlines route matching, and simplifies the codebase. By leveraging maps for method-handler associations, we achieve faster lookup times and improved runtime performance.
Implementation Details:
P.S This is my first-ever issue/proposal so feel free to correct and educate me in case I am wrong or missing something!
P.S.S @alexedwards In case this proposal seems reasonable I will be more than happy to create a PR :)
The text was updated successfully, but these errors were encountered: