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.

htm/mini tradeoff

See original GitHub issue

Maybe I am missing the point of htm/mini, but I can’t justify the tradeoff here. It saves 150 bytes, but adds 10 conditionals, which kind of make the code little more verbose.

Do we have a future plan to expand the main version to consider keeping mini version? I am guessing we might see more adoption of mini version if we add more features to main version.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
heyheyhellocommented, Apr 18, 2020

@Grafikart I’d recommend explicitly cloning the nodes rather than disabling cache:

const btn = html`
  <button class="btn-gradient"><span>Hello</span></button>`

const items = [1, 2, 3]
return html`
  <div>
    ${items.map(b => btn.cloneNode(true))}
  </div>`

While we all appreciate htm as a parser, it’s actually very expensive. The caching step can save lots of work. Try putting yourself in htm’s place and imagine parsing your <button... call through the 292 lines of code (build.mjs) to generate your DOM node, each time. That’s a lot of wasted work, and it would be a lot more efficient to leverage the browser to clone nodes for you - promise it’ll be faster than having htm do all the work again and again.

https://codesandbox.io/s/happy-pare-hgqkc?file=/src/index.js

2reactions
Grafikartcommented, Mar 15, 2020

I’m currently using mini cause the “normal” version seems to have a cache that creates problem if your h() function render a DomElement. Indeed htm will reuse the last return and the same dom reference will be used.

const items = [1, 2, 3]
    return html`<div>
    ${items.map(b => html`<button class="btn-gradient"><span>Hello</span></button>`)}
    </div>`

Since nothing change for the button, the method h() would be called once 😦 If mini disappear maybe we should have a way to completely disable cache (maybe in the bind function)

Read more comments on GitHub >

github_iconTop Results From Across the Web

tradeoff - Wiktionary
An advantage or improvement that necessitates the corresponding loss or degradation of something else. Improved graphics at the expense of battery life was...
Read more >
Archive of Retired Experiments - CSUF Psychology Department
New tests of cumulative prospect theory and the priority heuristic: Probability-outcome tradeoff with branch splitting. Judgment and Decision Making, 3, 304-316 ...
Read more >
An overview of the time trade-off method: concept, foundation ...
An overview of the time trade-off method: concept, foundation, and the evaluation of distorting factors in putting a value on health.
Read more >
Hierarchical Temporal Memory Based Predictive Model and ...
This trade-off is analyzed in terms of the SP execution speed and is shown ... state of the HTM mini-column or contents of...
Read more >
Energy Efficient Neocortex-Inspired Systems with On-Device ...
an HTM mini-column, (b) A waveform diagram demonstrating the ... may trade-off the network computational speed, consumed power, and network throughput.
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