question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Continuing from #182 and focusing on h.

h is in charge of returning a new vnode. Currently it exposes 2 additional features if I may say:

  1. It handles splats (varargs) of children.
  2. It concatenates contiguous string and number children into one text node.

Both features have a performance impact.

Splats

It’s basically here to support how some jsx transformers work. My feeling is they do it this way because it makes parsing/codegen easier for them.

Pros Cons
• Support all jsx transformers (react-compliant) • Slow (http://jsperf.com/function-signatures)
• More bytes

It has been discussed for the babel jsx transformer a while ago: https://github.com/babel/babel/issues/2034. The babel team didn’t do anything on this, @substack developed his own babel transformer for this specific case: https://github.com/substack/babel-plugin-jsx-factory.

We could either simply drop splats support and align with a clean vdom function signature. This would involve changing of babel transformer and investigate if webpack transformer supports this.

Or we could, as a mentioned here wrap h in a hjsx function that just handle splats, for those who really want to use it.

Concatenation

It concatenates string and number children into one text node.

Pros Cons
• Less nodes to diff • Additional memory
• Additional processing
• More bytes

It feels that having so many string/number contiguous nodes that there is a real performance benefit to merge them is less than obvious. Still, it allocates a stack and process it for each h call which has a non-negligible performance impact and gc stress.

EDIT: I’m talking about the internal stack here. I wrongly believed it was needed for concatenation, but it’s in fact because of how hyperx make calls to h. So everything here applies to ‘hyperx’ nested children handling instead of concatenation.

My advice on this would be to simply drop it and compare hyperapp diff benchs before and after.

Related

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:28 (28 by maintainers)

github_iconTop GitHub Comments

4reactions
jorgebucarancommented, Apr 15, 2017

I was able to get it down to this:

export default function (tag, data) {
  var children = []

  for (var i = 2; i < arguments.length;) {
    push(arguments[i++], children)
  }

  return typeof tag === "string"
    ? {
      tag: tag,
      data: data || {},
      children: children
    }
    : tag(data, children)

  function push(node) {
    if (Array.isArray(node)) {
      for (var i = 0; i < node.length; i++) {
        push(node[i], children)
      }
    } else if (node != null && node !== true && node !== false) {
      children.push(node)
    }
  }
}

but there was no perf advantage and not a big byte difference.

2reactions
selfupcommented, Apr 15, 2017

Also for performance using switch over if else if else can be a an easy win

As well as if (something === undefined) over if (!something) which will give a 15% improvement

Read more comments on GitHub >

github_iconTop Results From Across the Web

H-Optimize™ - Leverage Nutrition
The key ingredient in H-Optimize™ is DIM, a highly concentrated compound derived from cruciferous vegetables. DIM is proven to support healthy estrogen levels ......
Read more >
H-infinity methods in control theory - Wikipedia
H ∞ (i.e. "H-infinity") methods are used in control theory to synthesize controllers to achieve stabilization with guaranteed performance.
Read more >
Video Encoding Best Practices: 6 Practical Tips for Optimizing ...
We're sharing 6 tips for optimizing your video encoder settings for latency, bandwidth and picture quality so you can deliver video with confidence....
Read more >
Optimizing the human learnability of abstract network ... - PNAS
Here, we present a computational framework for simulating the optimization of human network learning by intentionally emphasizing or exaggerating some ...
Read more >
Optimizing H2, D2, and C2H2 Sorption Properties by Tuning ...
(17−20) An effective strategy for optimizing H2, D2, and C2H2 sorption is to synthesize MOFs with different pore sizes by controlling the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found