dtm2: introduce parsed runtime template manager#27011
dtm2: introduce parsed runtime template manager#27011GGRei wants to merge 3 commits intovlang:masterfrom
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb544c3fcc
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if source_path := m.resolved_template_paths[template_path] { | ||
| return source_path |
There was a problem hiding this comment.
Revalidate cached template paths before reuse
This returns a previously cached source path without re-running os.real_path/ensure_path_inside_template_dir, so the safety check is effectively one-time. If a template file is valid on first render and later replaced with a symlink to a file outside template_dir, subsequent renders can read outside content via os.read_file during recompilation, violating the module's documented directory restriction.
Useful? React with 👍 / 👎.
| } | ||
| path := signature[second_sep + 1..line_end] | ||
| stat := os.stat(path) or { return false } | ||
| if stat.mtime != signature[offset..first_sep].i64() || stat.size != u64(size) { |
There was a problem hiding this comment.
Invalidate cache on content changes, not only mtime+size
Freshness checking relies only on stat.mtime and stat.size. A template/include rewrite that keeps the same byte length within the same filesystem second will be treated as unchanged, so expand() can keep serving a stale compiled tree even though file contents changed. This is a real runtime correctness issue for rapid edits and autosave workflows.
Useful? React with 👍 / 👎.
|
I reworked the points raised by Codex. If there is anything else that needs to be changed, let me know. Otherwise, from my side this is ready for review/integration. |
This PR introduces
x.templating.dtm2, a modernized runtime template manager for V.The existing
x.templating.dtmmodule was originally my older contribution. I wanted to revisit it now with a cleaner architecture, better performance characteristics, and a simpler migration path for existing users.DTM2 keeps the same core idea: templates remain normal files on disk and can be changed without recompiling the application. The main architectural change is that DTM2 caches parsed template trees instead of rendered HTML responses, removing the old async rendered-cache server from the main rendering path.
The legacy
x.templating.dtmAPI remains available for compatibility and now delegates rendering internally to the DTM2 engine, so existing users can migrate progressively.Main points:
x.templating.dtm2x.templating.dtmsource-compatibletemplate_dirValidation run locally:
./v fmt -won touched V files./v vet vlib/x/templating/dtm2./v test vlib/x/templating/dtm2./v test vlib/x/templating/dtm./v -prod test vlib/x/templating/dtm2./v -prod test vlib/x/templating/dtmdev,prod, andprod_o2modes