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

Use accumulator on raw_html #588

Merged
merged 2 commits into from
Aug 9, 2024
Merged

Conversation

ypconstante
Copy link
Contributor

Today raw_html creates a new list wrapping up the sibling current html value before adding the current node data, causing a small memory overhead.

This PR moves raw_html to use an accumulator, simplified build_raw_html a bit by always expecting a list and merged tag_for into the only build_raw_html that was using it.

##### With input big #####
Name                   ips        average  deviation         median         99th %
bench (pr)           48.88       20.46 ms     ±6.66%       20.37 ms       25.04 ms
bench (main)         43.07       23.22 ms    ±15.12%       22.69 ms       30.49 ms

Comparison:
bench (pr)           48.88
bench (main)         43.07 - 1.13x slower +2.76 ms

Memory usage statistics:

Name            Memory usage
bench (pr)          12.12 MB
bench (main)        12.50 MB - 1.03x memory usage +0.39 MB

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

##### With input medium #####
Name                   ips        average  deviation         median         99th %
bench (pr)          219.61        4.55 ms     ±6.63%        4.47 ms        5.58 ms
bench (main)        141.74        7.06 ms    ±20.26%        6.46 ms       10.27 ms

Comparison:
bench (pr)          219.61
bench (main)        141.74 - 1.55x slower +2.50 ms

Memory usage statistics:

Name            Memory usage
bench (pr)           3.77 MB
bench (main)         4.08 MB - 1.08x memory usage +0.30 MB

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

##### With input small #####
Name                   ips        average  deviation         median         99th %
bench (pr)          955.98        1.05 ms    ±19.26%        1.06 ms        1.59 ms
bench (main)        732.85        1.36 ms    ±24.18%        1.50 ms        2.10 ms

Comparison:
bench (pr)          955.98
bench (main)        732.85 - 1.30x slower +0.32 ms

Memory usage statistics:

Name            Memory usage
bench (pr)         774.63 KB
bench (main)       877.17 KB - 1.13x memory usage +102.54 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.

Nice! Thank you!

I added a minor suggestion. Not sure if it will make any difference in memory.

lib/floki/raw_html.ex Outdated Show resolved Hide resolved
Co-authored-by: Philip Sampaio <philip.sampaio@gmail.com>
@philss philss merged commit 28c9ed8 into philss:main Aug 9, 2024
15 checks passed
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