Remove unnecessary explicit receiver in Html2Text.convert#30
Merged
Conversation
This makes subclassing Html2Text easier as `convert` does not have to be reimplemented.
mscrivo
added a commit
that referenced
this pull request
Jul 8, 2026
Profiling Html2Text.convert on the 1.4MB huge-msoffice fixture showed
GC accounting for 41% of wall time, driven by 1.37M object allocations
per convert — mostly node.name.downcase being recomputed ~19 times per
node across iterate_over, prefix_whitespace, suffix_whitespace and
next_node_name, plus per-node Array/map/compact/join churn.
Changes, all behavior-preserving (output is byte-identical on every
spec fixture):
- iterate_over computes node.name.downcase once per node and reuses it
- children are appended into a single mutable string instead of
building an Array, mapping, compacting and joining per node
- suffix_whitespace calls next_node_name once instead of twice for
br/div nodes
- merged duplicate h1-h6/p case branches, removing the need for the
Lint/DuplicateBranch disables
- dropped no-op /im regex flags and simplified /\n\n\n*/ to /\n{3,}/
Method signatures and return types are unchanged so subclasses that
override these methods (supported since #30) are unaffected; new specs
pin those extension points, and were verified to pass against the old
implementation as well.
Benchmarks (Ruby 4.0.5, arm64 macOS):
huge-msoffice (1.4MB) x5: 0.852s -> 0.522s (1.63x)
full_email (15KB) x500: 0.340s -> 0.269s (1.26x)
allocations (1x 1.4MB): 1,367,401 -> 642,896 (2.1x fewer)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes subclassing Html2Text easier as
convertdoes not have to be reimplemented.