-
Notifications
You must be signed in to change notification settings - Fork 792
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
What is the point of avoiding the semicolon in concat_javascript_sources #300
Comments
I think this sounds like a great idea. I feel like the walk in Since the common problem with concatenating JavaScript files is the lack of semicolons, automatically adding one (that, like Sam said, will then be removed by the minifier if it's unnecessary) seems on the surface to be a perfectly fine speed optimization. @SamSaffron did you purposefully keep the two separate shift operators in your optimized example? I'm wondering why we wouldn't just collapse them down into one, a la: def concat_javascript_sources(buf, source)
if buf.bytesize > 0
buf << ";\n"
end
buf << source
end I benchmarked the difference in a little toy example that I'm posting below. Granted it's a toy example using StringIO, but reducing it down to one call significantly speeds up the operation. require "benchmark/ips"
str = StringIO.new
str2 = StringIO.new
Benchmark.ips do |x|
x.report("double") { str << ";"; str << "\n" }
x.report("single") { str2 << ";\n" }
x.compare!
end
|
yeah, that was a bit lazy of me Michael, yeah a single shift operator would On Sun, May 15, 2016 at 7:01 AM, Michael Herold [email protected]
|
This seems fine, send a patch? |
@SamSaffron I was debugging the same thing and figured out that the issue is unicode (in case you were curious), here's a PR for that: #311 |
Has a check for
I was debugging our painfully slow reload times in Discourse when running qunit.
Essentially after any edit of any js file if we reload
/qunit
it takes us about 10 seconds for the page to render.Change concat javascript sources to
And we shave off 6 or so seconds, that is huge.
So I wonder, why not simply do:
Sure, you have a few extra newlines and semicolons, but the minifier will remove them anyway so no harm. And no need to walk backwards through all these strings which is surprisingly inefficient in Ruby.
cc @schneems
The text was updated successfully, but these errors were encountered: