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

Codegen: don't use init flag for string constants #9808

Merged
merged 4 commits into from
Oct 30, 2020

Conversation

asterite
Copy link
Member

@asterite asterite commented Oct 7, 2020

Also includes a small refacor.

For example if you have code like this:

puts FOO

FOO = "hello"

Then before this PR when reading FOO we would check whether it was initialized or not. This is not needed before a string literal doesn't need a special initialization, it's just data.

Like with #9801, it's not common to find code like the above but it is common that this happens because of order of require and the way the compiler works.

Benchmark (Int#to_s uses some constants that are string literals):

require "benchmark"

null = File.open(File::NULL, "w")

Benchmark.ips do |x|
  x.report("Int#to_s") do
    123456789.to_s(null)
  end
end

Before:

Int#to_s  89.91M ( 11.12ns) (± 4.98%)  0.0B/op

After:

Int#to_s  97.35M ( 10.27ns) (± 5.22%)  0.0B/op  fastest

@asterite
Copy link
Member Author

asterite commented Oct 7, 2020

Oh, it's failing with the Crystal constants which aren't in the program's AST. I'll fix that later.

@bcardiff
Copy link
Member

@asterite can you rebase on master?

@asterite
Copy link
Member Author

Sure! Just note that you can also do it because the branch is in this repo 😉

@asterite
Copy link
Member Author

Done!

@asterite asterite added this to the 1.0.0 milestone Oct 30, 2020
@asterite asterite merged commit 0752bdb into master Oct 30, 2020
@asterite asterite deleted the opt/string-constants branch October 30, 2020 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants