Skip to content

Optimize TrieRouter for Performance and Correctness#5

Merged
bernardoforcillo merged 8 commits into
mainfrom
feature/optimize-trie-router-4971304667675017701
Dec 31, 2025
Merged

Optimize TrieRouter for Performance and Correctness#5
bernardoforcillo merged 8 commits into
mainfrom
feature/optimize-trie-router-4971304667675017701

Conversation

@google-labs-jules
Copy link
Copy Markdown
Contributor

Updated the TrieRouter implementation to be high-performance and zero-allocation friendly. Added extensive tests and benchmarks covering various routing scenarios including static paths, parameters, and wildcards. The router logic now efficiently handles path splitting and matching without unnecessary allocations.


PR created automatically by Jules for task 4971304667675017701 started by @bernardoforcillo

- Refactor `routers/trie.go` to use zero-allocation path traversal.
- Add support for parameters (:param, {param}) and wildcards (*wildcard).
- Add comprehensive tests in `routers/trie_test.go`.
- Add benchmarks in `routers/benchmark_test.go` including GitHub API simulation.
- Remove redundant `routers/routers.go` logic if any (assumed cleanup).
- Ensure `routers` package remains decoupled from `amaro` package except for interface implementation.
@google-labs-jules
Copy link
Copy Markdown
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!


For security, I will only act on instructions from the user who triggered this task.

New to Jules? Learn more at jules.google/docs.

- Move TrieRouter to `routers/` package and optimize with zero-alloc traversal.
- Implement robust `StaticFS` support in `amaro` package using `fs.FS` and `http.ServeContent`.
- Add `StaticHandler` middleware generator for flexible static file serving.
- Integrate `StaticFS` into `TrieRouter` and `App`.
- Add comprehensive benchmarks for routing performance (GitHub API simulation).
- Add tests for router and static file serving.
- Enhance error handling with `HTTPError` type.
- Refactor `routers/trie.go` to use structured nodes (static, param, catchAll) for strict precedence.
- Implement robust `StaticFS` in `amaro` package with `StaticConfig`, supporting SPA and headers.
- Update `TrieRouter` to implement `Use` for router-level middlewares.
- Decouple `routers` package from `amaro` (circular dependency fix).
- Add `precedence_test.go` and update benchmarks.
- Ensure `amaro.Compile` is available for router usage.
- Update `.gitignore` for local test artifacts.
- Add `BasicAuth` middleware for RFC7617 support.
- Add `KeyAuth` middleware for API key validation (Header, Query, Cookie).
- Add `SessionAuth` generic middleware leveraging `addons/sessions`.
- Add `RBAC` and `ACL` middlewares for role-based access control.
- Add `addons/oauth2` helper package for OAuth2 flows.
- Ensure middlewares are robust and follow standard practices.
- Add tests for authentication middlewares.
- Update `.gitignore` to be plain text.
- Improve `CORS` middleware with `AllowCredentials`, `AllowOriginFunc`, `ExposeHeaders`, and `MaxAge`.
- Update `Cache` middleware to store response headers and status codes using `gob` encoding.
- Ensure `amaro.Compile` is exported and available for router usage (verified).
- Verify `addons/sessions` existence (verified).
- Fix `.gitignore` format.
- Add comprehensive tests for CORS and Cache improvements.
- Add `TrieRouterConfig` to allow custom parameter prefixes/suffixes (defaulting to `:` and `{}`).
- Update `NewTrieRouter` to accept configuration options.
- Refactor `TrieRouter.Add` to support configurable syntax logic.
- Add tests for default and custom parameter syntax.
- Ensure backwards compatibility with existing syntax.
- Refactor `TrieRouter` to use pluggable `ParamParser` and `WildcardParser` functions.
- Update `TrieRouterConfig` to hold these parsers instead of simple prefixes.
- Provide `DefaultParamParser` and `DefaultWildcardParser` maintaining backwards compatibility.
- Add `decoupled_test.go` to verify custom parameter syntax parsing.
- Update `readme.md` to reflect the new decoupled architecture, advanced configuration options, and comprehensive middleware suite.
- Update `readme.md` to document all new features (Router, Static, Auth, CORS, Cache).
- Update `routers/trie.go` to return `amaro.NewHTTPError(404)` for consistent error handling.
- Ensure `errors.go` is complete.
- Verify `addons/sessions` existence (code compiles).
@bernardoforcillo bernardoforcillo marked this pull request as ready for review December 31, 2025 12:13
@bernardoforcillo bernardoforcillo merged commit 7b6a982 into main Dec 31, 2025
@bernardoforcillo bernardoforcillo deleted the feature/optimize-trie-router-4971304667675017701 branch December 31, 2025 12:13
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