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
Increase the amount of freezing #1233
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
require "mail" | ||
require "roda" | ||
require "tilt" | ||
require "tilt/erubi" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,6 +210,8 @@ def create_certificate | |
).map(&:to_pem) | ||
end | ||
|
||
@@dns_zone = nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm surprised that this works. So existence of the variable is enough and .freeze does not freeze the value. It kinda defeats the purpose of freezing, but still better than what we have. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's because the type may change but not the existence of the class variable. I actually wrote this as a prototype. Like you, I found it unsatisfying, because there is interesting dynamic behavior that could fail at run time while modifying the class. I'm not sure if I want to do go through with this hack. |
||
|
||
def self.dns_zone | ||
@@dns_zone ||= DnsZone[project_id: Config.postgres_service_project_id, name: Config.postgres_service_hostname] | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this do 2 loops or is Ruby runtime smart enough to optimize it to single loop?
If it does 2 loops, you can do
to shave off few miliseconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does two passes, and that's what I want I think, IIRC
AUTOLOAD_CONSTANTS.each { Object.const_get(_1).freeze }
doesn't work, if future loaded constants patch ones previously frozen. I think one-passing it was the first thing I tried?