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

Optimize RawHTML.build_attrs/2 #505

Merged
merged 1 commit into from
Dec 18, 2023

Conversation

ypconstante
Copy link
Contributor

@ypconstante ypconstante commented Dec 17, 2023

While doing benchmarks on a Phoenix LiveView project, I saw that build_attrs/2 spent a lot of time running Function.info/1 to check if we wanted to skip the HTML.

This PR replaces Function.info a simple equals check to see if the value is the same @encoder.

:fprof results before

%                                                     CNT                           ACC                           OWN
[{ totals,                                           4183972,                     6249.692,                     6096.914}].  %%%
...
{[{{'Elixir.Floki.RawHTML','-tag_attrs/2-fun-0-',2},   10952,                     1101.148,                       43.927}],
 { {'Elixir.Floki.RawHTML',build_attrs,2},             10952,                     1101.148,                       43.927},     %
 [{{erlang,fun_info,1},                                21904,                      701.652,                       21.910},
  {{'Elixir.Floki.RawHTML',html_escape,1},             10952,                      355.450,                       10.954},
  {garbage_collect,                                      109,                        0.109,                        0.109},
  {suspend,                                               10,                        0.010,                        0.000}]}.

:fprof results after

%                                                     CNT                           ACC                           OWN        
[{ totals,                                           3698164,                     5472.400,                     5367.805}].  %%%
...
{[{{'Elixir.Floki.RawHTML','-tag_attrs/2-fun-0-',2},   10952,                      377.486,                       22.015}],
 { {'Elixir.Floki.RawHTML',build_attrs,2},             10952,                      377.486,                       22.015},     %
 [{{'Elixir.Floki.RawHTML',html_escape,1},             10948,                      355.356,                       10.951},
  {garbage_collect,                                       99,                        0.099,                        0.099},
  {suspend,                                               16,                        0.016,                        0.000}]}.

@philss philss merged commit 8496ccf into philss:main Dec 18, 2023
9 checks passed
@philss
Copy link
Owner

philss commented Dec 18, 2023

Good call! Thank you! 💜

@ypconstante ypconstante deleted the optimize-raw-html-build-attrs branch December 18, 2023 18:04
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