hyperapp icon indicating copy to clipboard operation
hyperapp copied to clipboard

Use node.append(child) instead of node.appendChild(child)

Open skanne opened this issue 3 years ago • 7 comments

Hi Jorge,

similar to PR 1036 I suggest replacing node.appendChild(child) with node.append(child). Difference explained here: https://dev.to/ibn_abubakre/append-vs-appendchild-a4m.

Benefit: 5 characters/bytes of code less.

Regards, Sven

skanne avatar Feb 28 '21 18:02 skanne

Since append() accepts plain DOMStrings, I wonder if it's possible to take advantage of it around here:

https://github.com/jorgebucaran/hyperapp/blob/9df1acafc0d5ac488e52ad92df4bdb47c4a40fcb/index.js#L131-L136

jorgebucaran avatar Mar 01 '21 03:03 jorgebucaran

Possibly. I'll spend some time on this and find out. I do see some potential around https://github.com/jorgebucaran/hyperapp/blob/9df1acafc0d5ac488e52ad92df4bdb47c4a40fcb/index.js#L105-L110 and https://github.com/jorgebucaran/hyperapp/blob/9df1acafc0d5ac488e52ad92df4bdb47c4a40fcb/index.js#L117-L123

But I need to wrap my head around it. High noon for me to try to understand all inner workings of Hyperapp's core. (Code comments would help, but are non-existent. Are you planning on documenting the core?)

skanne avatar Mar 01 '21 10:03 skanne

High noon for me to try to understand all inner workings of Hyperapp's core.

What do you need help with?

jorgebucaran avatar Mar 01 '21 10:03 jorgebucaran

Well, I need to walk through the code and see what happens. Never bothered to fully understand the concept of patching.

skanne avatar Mar 01 '21 10:03 skanne

It would seem to me that here, as with #1036 the more generic function is likely to be less performant. At the least, it must inspect argument types and branch, whereas the dedicated function for Nodes expects a Node.

l-cornelius-dol avatar May 27 '21 18:05 l-cornelius-dol

The performance difference really is neglible IMO. See https://www.measurethat.net/Benchmarks/Show/9176/0/js-append-vs-appendchild

skanne avatar May 28 '21 17:05 skanne

@skanne performance difference is about 12%, which is not critical for custom usage, but not for hyperapp(superfine)

sergey-shpak avatar May 29 '21 13:05 sergey-shpak