8000 Drop C extension by k0kubun · Pull Request #1146 · haml/haml · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Drop C extension #1146

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

Merged
merged 1 commit into from
Sep 27, 2023
Merged

Drop C extension #1146

merged 1 commit into from
Sep 27, 2023

Conversation

k0kubun
Copy link
Member
@k0kubun k0kubun commented Sep 27, 2023
  • One of the main advantages of the Haml C extension was its HTML escape implementation, but I ported its optimization to ERB::Escape in Ruby 3.2 and now Haml uses it Let Haml::Util.escape_html use ERB::Escape #1145.
  • The rest of the C extension exists for rendering attributes, but in most cases, the Haml compiler simplifies generated code and removes the need for the C extension. So it's not called a lot or important in the first place.
  • YJIT is getting better in recent versions. If you run this Ruby version with YJIT, the speedup obtained by writing this in C becomes smaller than running it without YJIT. I'd like to invest in YJIT's performance by turning Haml's attribute builder into a potential optimization target for YJIT.
  • It has some rb_funcall calls. As we optimize YJIT further, YJIT-optimized Ruby code might potentially outperform this C extension since Ruby -> C -> Ruby calls are somewhat expensive by nature.
  • Having a C extension generally makes it hard to support JRuby/TruffleRuby/Wasm. Ruby code is more maintainable than C.

@k0kubun k0kubun merged commit 6d71b6e into main Sep 27, 2023
@k0kubun k0kubun deleted the drop-c-ext branch September 27, 2023 07:51
@agrobbin
Copy link
agrobbin commented Oct 4, 2023

@k0kubun I think this might have introduced an issue with the handling of a hash value for :aria. On haml 6.1, this:

%div{ aria: { label: 'foo' } }

Would compile to this:

<div aria-label='foo'></div>

Now, on 6.2, it compiles to this:

<div aria='{:label=&gt;"foo"}'></div>

I think it's due to aria being missing here, but accounted for in the C extension.

@k0kubun
Copy link
Member Author
k0kubun commented Oct 4, 2023

Can you prepare a repository that reproduces it? I cannot reproduce your issue locally. We also have a test case similar to it https://github.com/haml/haml/blob/v6.2.0/test/haml/engine/old_attribute_test.rb#L387-L393 and it's passing.

$ irb -rhaml
irb(main)[01:0]> RUBY_DESCRIPTION
=> "ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]"
irb(main)[02:0]> Haml::VERSION
=> "6.2.0"
irb(main)[03:0]> Haml::Template.new { "%div{ aria: { label: 'foo' } }" }.render
=> "<div aria-label='foo'></div>\n"

@k0kubun
Copy link
Member Author
k0kubun commented Oct 4, 2023

OK, I managed to make a reproducible issue from the code you pointed out:

$ irb -rhaml
irb(main)[01:1]" Haml::Template.new { <<~EOS }.render
irb(main)[02:1]"   - hash = { aria: { label: 'foo' } }
irb(main)[03:1]"   %div{ hash }
irb(main)[04:0]> EOS
=> "<div aria='{:label=&gt;&quot;foo&quot;}'></div>\n"

I don't think the %div{ aria: { label: 'foo' } } case is broken, but I can fix that one instead.

@k0kubun
Copy link
Member Author
k0kubun commented Oct 4, 2023

Fixed in v6.2.1.

@k0kubun
Copy link
Member Author
k0kubun commented Oct 4, 2023

Fixed another aria-related issue in v6.2.2.

@agrobbin
Copy link
agrobbin commented Oct 4, 2023

Whoops, yes that is actually exactly what my templates are doing (technically %div{ **hash }), when I reduced it down to it's simplest version, I went a step too far. Thanks for the quick work here regardless!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0