ViewComponent outperforms inline_svg #232
JamesChevalier
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
This is crazy! Awesome work digging in to this. Before I go and migrate all of railsdevs, I have a few questions. I'm assuming the massive speed up is because
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
👋 I discovered inline_svg through this project & started implementing it in mine. Then I wondered how it compared to setting up SVGs with ViewComponent. I thought I'd share what I found, since you also use ViewComponent...
I used the solid 'check' SVG from Heroicons:
I set up a view_component that accepts
svg_class
:and swapped out the classes with
<%= @svg_class %>
in the SVG tag:Then I ran
Benchmark.ips
against both versions:with a big performance difference:
I opted to create a component for each SVG image in the format
SvgCheckComponent
,SvgDeleteComponent
, etc. The erb for each component is the SVG tag with the class passed as a variable likeclass="<%= @svg_class %>"
and I render them on pages by swapping out theinline_svg_tag
with<%= render SvgCheckComponent.new(svg_class: "inline-block w-6") %>
Beta Was this translation helpful? Give feedback.
All reactions