Skip to content

Optimize allocations in next_siblings - #66

Open
tysg wants to merge 1 commit into
aantron:masterfrom
ahrefs:perf/optimize-next-siblings
Open

Optimize allocations in next_siblings#66
tysg wants to merge 1 commit into
aantron:masterfrom
ahrefs:perf/optimize-next-siblings

Conversation

@tysg

@tysg tysg commented Dec 15, 2025

Copy link
Copy Markdown

This PR optimizes allocations for Soup.next_siblings at the cost of code elegance :) Similar to #64 , we found this function when profiling allocations in our internal code.

Our code heavily uses Soup.next_element which builds the prefix list then discards it. So it's kinda of a waste.

This PR replaces split_at_identity with specialized suffix_after_identify and prefix_before_identity, so that in suffix_after_identity no new list is allocated.

Obviously this looks like an edge for day-to-day use. So please feel free to close this PR if the tradeoff doesn't make sense.

used by next_element on readability hot path
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.

1 participant