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

Add sass support via sass-embedded #1911

Merged
merged 3 commits into from
May 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review feedback
  • Loading branch information
ntkme committed May 15, 2023
commit f15392a205aad5d14cb7be1bb230af709d8e82b6
1 change: 1 addition & 0 deletions lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ def render(engine, data, options = {}, locals = {}, &block)
end

if content_type
# sass-embedded returns a frozen string
output = +output
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this a problem before, that this string was frozen?

Maybe we should commit this change separately? With a test for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is due to google-protobuf gem decodes the output as frozen string. There is a performance concern on eagerly unfreezing when not necessary. Therefore, sass-embedded returns the css output as frozen string as is, for which dependencies need to unfrozen the string as needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we only unfreeze when sass-embedded is used? Can we at least add a comment to the code with the above information?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment.

As for the +string method:

Returns self if self is not frozen.
Otherwise. returns self.dup, which is not frozen.

I did a microbenchmark on different ways to write this, and output = +output is the most performant one:

       user     system      total        real
s.freeze; s = s.dup if s.frozen?;	  1.553977   0.006994   1.560971 (  1.561001)
s.freeze; s = +s if s.frozen?;		  0.919195   0.002047   0.921242 (  0.921248)
s.freeze; s = +s;			  0.763196   0.001567   0.764763 (  0.764776)

output.extend(ContentTyped).content_type = content_type
end
Expand Down