xijo / reverse_markdown

Ruby gem to convert html into markdown
Do What The F*ck You Want To Public License
628 stars 118 forks source link

Avoid traversing back up the tree #60

Closed craig-day closed 9 years ago

craig-day commented 9 years ago

We are traversing the document top-down, so we shouldn't ever need to traverse back up. In very large documents, traversing back up can be expensive. This will pass around a state that can be used to track parent information rather than ascending back up the tree.

:warning: This is something I would consider worthy of a major version bump, as it changes the API a little bit. Anyone with currently built custom converters will encounter errors until they modify them to accept the state argument and then pass that argument to treat_children

Some performance numbers for parsing this document before

unknown tag mode :pass_through
time: 0.535165

unknown tag mode :drop
time: 0.577383

unknown tag mode :bypass
time: 0.539775

after

unknown tag mode :pass_through
time: 0.080481

unknown tag mode :drop
time: 0.077927

unknown tag mode :bypass
time: 0.051546
grosser commented 9 years ago

:+1: @xijo

xijo commented 9 years ago

@craig-day great idea, I love it! :+1:

I'll update the changelog and release it as a major version bump.