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

Allow functions/filters to access their constant arguments at compile time #940

Open
clarfonthey opened this issue Oct 18, 2024 · 2 comments

Comments

@clarfonthey
Copy link
Contributor

clarfonthey commented Oct 18, 2024

Basically following up this discussion: getzola/zola#2581 (comment)

Right now, functions and filters don't have special access to constant arguments, which means that, for example, regex filters will have to compile their expression every time they run. There are ways around this, but what feels reasonable is determining what arguments are constant and then passing those during compilation to affect the final result.

Another option could just be to have a lazy cell in the function state that stores a compiled Regex and just replaces it if the pattern changes, but it feels like being able to optimize the functions further could help performance for large cases. Effectively, we could pre-evaluate large chains of logic if we do this right.

@Keats
Copy link
Owner

Keats commented Oct 18, 2024

Easiest way (I think) would be to define a struct for the filters/tests using regex and store the compiled versions in a hashmap in that struct. I don't know if people are using those filters/tests with dynamic patterns though?

@clarfonthey
Copy link
Contributor Author

That's mostly why I proposed using a static cell instead of a hashmap: if they do end up doing it dynamically, it'll recompile every time, but in the common case where it's constant, they won't.

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

No branches or pull requests

2 participants