Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache generated code #689

Closed
wants to merge 1 commit into from
Closed

Cache generated code #689

wants to merge 1 commit into from

Conversation

Kijewski
Copy link
Contributor

  • Speeds up compilation of a project a lot, when only one, a few, or no templates were changed.
  • Speeds up compilation a little even for an initial compilation.
  • Far better error messages in generated code.
  • The generated code is easily debuggable.

@Kijewski
Copy link
Contributor Author

I'll tidy up the PR after y'all tell me what you think, e.g. introducing the use of IndexMap, and deriving Hash in their own commits.

* Speeds up compilation of a project a lot, when only one, a few, or no
  templates were changed.
* Speeds up compilation a little even for an initial compilation.
* Far better error messages in generated code.
* The generated code is easily debuggable.
@Kijewski
Copy link
Contributor Author

Kijewski commented May 24, 2022

I could suppress the newly generated clippy warnings, too, but actually clippy is quite right with its warnings. Same condition in multiple elif-blocks, calculating X / X, etc. are 99% programming errors (outside of tests).

@djc
Copy link
Owner

djc commented May 24, 2022

Do you have benchmark numbers? In a bunch of other projects, I've adopted a different approach that I think might be better: generate code in an integration test. Here's one example, I've done a few others if you're interested:

mattsse/chromiumoxide#80

So the idea would be that we have an askama_build crate that contains the generator and other stuff, which offers a builder API that lets you pass a string like crate::foo::Bar with a Path to the template for that type, and this would generate the Template implementations into a file (formatted with rustfmt) written into the src dir as part of an integration test. This is nice because:

  • No build script, build scripts slow down compilation pipelines and are a supply chain hazard
  • No recompilation of the templates unless needed, no procedural macro expansion except at test time
  • Integration test run in CI makes sure that the generated code is never out of date

@Kijewski Kijewski marked this pull request as draft June 16, 2022 17:06
@Kijewski Kijewski closed this Jul 20, 2022
@Kijewski Kijewski deleted the pr-caching branch September 26, 2022 13:00
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.

2 participants