Replies: 7 comments 9 replies
-
I've never really had needs for such complexity - with funcmaps just being maps it's easy to add/remove functions. But I do not remember a case where I wanted to remove functions I did need to replace functions with others to facilitate backward compatible introduction of sprig into existing categories. It would be beneficial to support easily preventing some function/group but loading the rest. What is a problem is the compile time dependencies for things like the crypt functions and this mechanism would not address that - unused functions would still be compiled in as the resolution of which to load would be runtime and potentially dynamic. If dynamic of template initiated loading is supported that should be off by default for security needs when templates are user supplied which would be the most common case. |
Beta Was this translation helpful? Give feedback.
-
I will start working on this in a few days/weeks to give people more time to discuss the RFC if needed. :) |
Beta Was this translation helpful? Give feedback.
-
UPDATE: Some IRL (IRL is a curious thing that forces me to go outside of my cave) - I'll take my time this week. I probably will start a POC (proof of concept) this week and propose the pull request here to get feedback! See you 🌱 💜 |
Beta Was this translation helpful? Give feedback.
-
UPDATE: After somes complication, I'm back ! So after takes pros and cons for import based stractegy (and to excluse crypto as well 🛴) So that is the Setup and Usage in Main Application (
|
Beta Was this translation helpful? Give feedback.
-
Why does the crypto import not auto register itself in the registry on import then all that is needed is to import it. None of the other code. |
Beta Was this translation helpful? Give feedback.
-
UPDATE: A Huge pull request to migrate all stuffs are created #46 I will test the branch with my personal projects to test performance and devex, and also start a branch for documentation update 📜 |
Beta Was this translation helpful? Give feedback.
-
UPDATE: The registry system has released on v0.5.0 🎉 Thanks for all to have contributed to the RFC, reviews, and feedbacks 🌱 💜 If you have concerns don't hesitate to talk about on release discussion or open an issue ! |
Beta Was this translation helpful? Give feedback.
-
Introduction
This RFC introduces enhancements to the loader feature of the
go-sprout/sprout
project, focusing on optimizing the management and execution of functions within Go templates. This aims to prevent the unnecessary loading of functions and enhance developer control over function management.Important
Actual implementation selected are available here https://github.com/orgs/go-sprout/discussions/31#discussioncomment-10013601
Tip
RELEASED: The registry system has released on v0.5.0 🎉 Thanks for all to have contributed to the RFC, reviews, and feedbacks 🌱 💜
If you have concerns don't hesitate to talk about on release discussion or open an issue !
Motivation
In large-scale applications, the efficiency of template processing is crucial. Loading all available functions into every template instance not only affects performance but also increases memory usage unnecessarily. This proposal seeks to provide a solution where developers can selectively load functions, optimizing resource use and processing speed.
Proposal
We propose the development of a selective function loading mechanism within the
loader
structure, allowing developers to specify which functions are loaded into a template environment.And also have a custom function loading to enhance the flexibility and utility of
sprout
, we propose allowing developers to load custom functions specific to their projects. This would enable them to not only utilize but also extendsprout
's core functionalities according to their unique requirements, thereby maximizing the adaptability and application of the loader system across diverse scenarios.Technical Description
func(...any) (any, error)
(must in sprig). The Loader will automatically register a safe version of the functionfunc(...any) any
.Code example
This code is an example and may be subject to changes.
Benefits
Drawbacks
Alternatives Considered
Open Questions
a. For the
LoadFunctionFromStruct
method, should a specific prefix, such asTemplateFunc
, be mandated to explicitly secure and clarify function purposes?b. For the
WithLoaderGroup
method, which is better: using a string-based identifier (e.g.,"math"
) or a type-based identifier (e.g.,sprout.MathFunctionGroup
) for defining function groups?c. For the
LoadFunction
method, should function identification rely on string-based names (e.g.,"print"
) or type-based identifiers (e.g.,sprout.PrintFunction
)? What are the implications of each approach for system robustness and usability?Future Extensions
Intelligent Preloading: Based on a pre-read of the template, automatically determine which functions to load for a template.
Resource Monitoring: Tools to monitor the performance impact of loaded functions on template processing.
Conclusion
Your insights and comments are crucial for refining and improving the proposed loader feature, ensuring it meets the needs and expectations of a broad range of developers. Please share your thoughts on the proposed functionalities, any concerns you might have, and any additional features you believe should be considered. This collaborative approach is essential for us to achieve a robust and versatile implementation. We look forward to your contributions and are excited to see how together we can enhance the capabilities of sprout.
Beta Was this translation helpful? Give feedback.
All reactions