You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit bbe99c8
Browse filesBrowse the repository at this point in the historyBrowse files
Reduce allocations in iterate_over for ~1.6x faster conversion
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>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
### Changed
9
9
- Require Ruby 3.3+; CI now tests Ruby 3.3, 3.4 and 4.0 ([#42](https://github.com/soundasleep/html2text_ruby/pull/42))
10
10
- Update development dependencies (rubocop 1.88, nokogiri 1.19 in the lockfile), removing the transitive `rexml` dependency ([#42](https://github.com/soundasleep/html2text_ruby/pull/42))
11
+
- Reduce object allocations in `iterate_over` for ~1.6x faster conversion of large documents ([#41](https://github.com/soundasleep/html2text_ruby/pull/41))
12
+
13
+
### Added
14
+
- Specs covering subclass overrides of `prefix_whitespace`, `suffix_whitespace`, `iterate_over`, `wrap_link` and `image_text`, plus unit specs for `fix_newlines` and `replace_entities` ([#41](https://github.com/soundasleep/html2text_ruby/pull/41))
0 commit comments