Repository navigation
Conversation
|
@tagliala please take a look when you have time |
|
@javierjulio i see there are conflicts, once you do initial review i can rebase it on master |
javierjulio
left a comment
There was a problem hiding this comment.
@senid231 thank you. We'd welcome improvements to Arbre, our main concern is avoiding any breaking changes and keeping compatibility. I ran a review with Codex on Sol 6.2 which I've posted below.
The shared buffer cuts render allocations substantially. In a local 500-row, 44-cell table benchmark, render allocations fell from about 667,000 to 22,000 with identical HTML. The cases below still differ from the base revision.
- Rendering overrides are skipped. Redefining
Tag#opening_taghas no effect even on the first render because the method owner stays the same. After the first render, the cache also misses ato_soverride prepended to an element’s singleton class or added to an already-included module. Render flags - Documents bypass the
Tag#to_schain. A wrapper prepended toTag#to_spreviously ran after the doctype.Document#to_snow skips it. A custom doctype returned as a plain string also changes the result’shtml_safe?value fromfalsetotrue. Document - Void tags can raise while rendering discarded text.
input "☃".encode("UTF-16LE").html_safepreviously rendered<input/>. The shared writer appends the text before discarding it, which raisesEncoding::CompatibilityError. Tag writer - Attribute serialization changes. An override of
tag.attributes.to_sno longer controls the rendered attributes. Also, if an attribute value’sto_sadds an attribute, the new writer raises because it is iterating over the live hash. The old serializer converted values after flattening the attributes. Tag writer · Attributes - Indentation hooks change behavior. A nested tag with
parent?overridden to returnfalsegains two spaces. The writer also readsindent_levelbeforeopening_tag, reversing the previous order. A customindent_levelof-1now selects the last entry inSPACESwhere it previously raisedArgumentError. Child depth · Tag indentation - Text node behavior changes. A
Stringsubclass with a customto_srenders the underlying string when nested in a tag. The old renderer used the override. Also, readingchildrenon a frozen text node now raisesFrozenErrorif the collection has yet to be initialized. Text node · String conversion - Default tag names become frozen.
Span.new.tag_name.replace("em")previously changed that element’s tag name. It now raisesFrozenError. Tag name cache Tag#buildchanges its return value.Div.new.build("hello")returned{}and now returnsnil. A custombuildmethod that uses the result ofsupercan break. Tag builder
Three changes would make these paths easier to maintain:
- Share tag construction between
build_tagandarbre_insert_tag. Both assign the parent, enter the builder context, and handle block arity and return values. Builder methods - Keep separator and escaping rules in one place. The new top-level and nested attribute writers repeat them. Attributes · Nested attributes
- Keep builder dispatch decisions with the builder. The render cache now also decides when to bypass
build, so future builder changes require edits to rendering code. Render flags
Please add regression specs for the compatibility cases above.
Each subtree's HTML used to be copied several times per nesting level, and every text node built a throwaway Arbre::Context. Elements now write into one buffer, and classes that override a rendering or building hook keep going through that override, so output and API stay unchanged. Co-Authored-By: Clanker
Co-Authored-By: Clanker
Builder methods hand their argument array straight to Tag#build's body when build is still Arbre's own, and Element#build takes an anonymous splat it never reads. Overridden or extended builds go the usual way. Co-Authored-By: Clanker
Co-Authored-By: Clanker
Attributes are written in one pass, the opening and closing tags are written inline, and the render-flag lookup reads two instance variables instead of building an array. The override checks stay in place. Co-Authored-By: Clanker
Co-Authored-By: Clanker
Overrides are now detected by comparing each method, and the supers it calls, with Arbre's original, so redefining a hook in place or in a module included later also falls back. The builder fast path is gone: it changed Tag#build's return value and saved little time. Co-Authored-By: Clanker
0672777 to
7a65bdf
Compare
|
Thanks for the review. I pushed 7a65bdf, which addresses each point, and rebased on master. The examples under "compatibility with the original renderer" in
The 500-row table now allocates 563k objects (2.08M on 2.2.1). |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #756 +/- ##
===========================================
- Coverage 100.00% 99.09% -0.91%
===========================================
Files 17 18 +1
Lines 459 774 +315
===========================================
+ Hits 459 767 +308
- Misses 0 7 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@senid231 before posting another review, I've opened #761 with additional integration tests to ensure Arbre rendering compatibility before and after this PR. Since you seem to have a deeper understanding of Arbre, it would help to get your review and thoughts there and to also run it against your branch and give any feedback. Thank you. |
Rendering a large tree now allocates a fraction of the memory, and the output stays byte-identical. Before this change, every nesting level copied its subtree's HTML about five times (
indent,ElementCollection#to_s,html_safe), and each text node built a throwawayArbre::Context. Related to #67.Elements write into one shared buffer, and the depth is passed down instead of walked up the parent chain. An object renders through the original methods when any rendering hook differs from Arbre's own. Each hook, and every super it calls, is compared with the original method, so this covers subclasses, a hook redefined in place, singleton methods,
extend, and modules included or changed after the first render.Results on a 500-row by 44-cell table:
An ActiveAdmin 4 index page with 500 rows allocates 1.08M objects instead of 2.36M, and its HTML is identical.
Verification: the compatibility examples in
spec/arbre/unit/rendering_spec.rbalso pass on 2.2.1. 50 edge cases match 2.2.1 byte for byte under ActiveSupport 8.1 and 7.1. ActiveAdminv4.0.0.beta23's suite passes (1588 examples).