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 raw html padding for small depths #589

Merged
merged 3 commits into from
Sep 4, 2024

Conversation

ypconstante
Copy link
Contributor

Today on every pad_increase we're computing the new pad value using String.duplicate. This PR precomputes the pad increase string for values under 100 depth (arbitrary value), providing a small performance and memory improvement.

Changes:

  • Move line ending from padding map to a separated variable
  • Remove line_ending/1 function and use the line_ending value directly
  • Replace padding map variable with pad string value
  • Remove leftpad/1 function and use the pad value directly
  • Precompute pad_increase for depths under 100
##### With input big #####
Name                   ips        average  deviation         median         99th %
bench (PR)           57.32       17.45 ms    ±12.32%       17.01 ms       20.79 ms
bench (main)         48.80       20.49 ms     ±6.44%       20.37 ms       26.05 ms

Comparison:
bench (PR)           57.32
bench (main)         48.80 - 1.17x slower +3.05 ms

Memory usage statistics:

Name            Memory usage
bench (PR)          11.51 MB
bench (main)        12.12 MB - 1.05x memory usage +0.61 MB

**All measurements for memory usage were the same**

##### With input medium #####
Name                   ips        average  deviation         median         99th %
bench (pr)          227.80        4.39 ms    ±31.57%        4.78 ms        6.24 ms
bench (main)        221.93        4.51 ms     ±9.86%        4.39 ms        6.20 ms

Comparison: 
bench (pr)          227.80
bench (main)        221.93 - 1.03x slower +0.116 ms

Memory usage statistics:

Name            Memory usage
bench (PR)           3.45 MB
bench (main)         3.77 MB - 1.09x memory usage +0.32 MB

**All measurements for memory usage were the same**

##### With input small #####
Name                   ips        average  deviation         median         99th %
bench (PR)          1.31 K        0.76 ms    ±24.67%        0.77 ms        1.19 ms
bench (main)        0.98 K        1.02 ms    ±18.62%        1.04 ms        1.47 ms

Comparison:
bench (PR)          1.31 K
bench (main)        0.98 K - 1.34x slower +0.26 ms

Memory usage statistics:

Name            Memory usage
bench (PR)         677.02 KB
bench (main)       774.63 KB - 1.14x memory usage +97.61 KB

Copy link
Owner

@philss philss left a comment

Choose a reason for hiding this comment

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

Looks good! :shipit:

@philss philss merged commit e7f0d9d into philss:main Sep 4, 2024
15 checks passed
@philss
Copy link
Owner

philss commented Sep 4, 2024

@ypconstante thank you!

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