-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
Suggestion: Change Loggable logger initialization from lazy to eager #233
Comments
Thinking more about this, I understand the intention of minimizing memory use with the lazy initialization, but in many cases, I think it is premature optimization (not of speed but of memory usage). If I'm not mistaken, these loggers are very lightweight objects, and in many cases the number of classes including Loggable is not in an order of magnitude that would be significant with regard to memory usage. Given that it's also possible the number of classes would be high enough to care, I think the best solution is to provide an option. As for the default setting, my personal opinion is that the risk of |
I have posted a PR that I would think would be a good fix for this, at #239. |
I have closed my PR at #239, as it is was an incomplete solution. |
After thinking more about this, I think the best solution would be to just change the lazy initialization to eager initialization, rather than to make it an option. This would be much simpler than making it optional. Is the lazy initialization important to anyone? I have therefore changed the title of this issue from "Add install_eagerly method to Loggable" to "Change Loggable logger initialization from lazy to eager". @reidmorrison, could you let me know what you think about this? |
The |
Environment
The SemanticLogger::Loggable module provides an instance
logger
method that lazily initializes a@semantic_logger
instance variable. If the instance is frozen the first timelogger
is called, then an error like this is raised:One solution to this is to call
logger
somewhere in your constructor. That way the instance variable will be initialized before the object can be frozen. The following script can be used to illustrate this:It would be even nicer if there were an option to turn off lazy initialization, e.g.:
This would eliminate the need for the workaround in the constructor. This workaround would need to be in any class whose instances could potentially be frozen, which really means any class at all. As freezing objects becomes more prevalent, this will become more of an issue.
Alternatively, the nonlazy approach could be used by default, or possibly even be the only option.
The text was updated successfully, but these errors were encountered: