function renderGui()
{
label('hello')
if(button('click me'))
{
console.log('I have been clicked')
}
} function renderGui()
{
label('hello')
if(button('click me'))
{
console.log('I have been clicked')
}
}Another scenario outlined in the article of rendering a row of buttons, each with it's own click handler, that needs to allocate a lambda for each button every render. Alternatively, using map() and filter() also allocates lambdas and temporary arrays.
All this can be replaced with a simple for loop like:
for (item of items) {
if(!item.isClickable)
continue;
if(button(item.name)){
console.log(item.name)
}
}
Compare this to the React-ish pseudocode: items.filter(item=>item.isClickable).map(item=><button onClick={()=>console.log(item.name)} >{item.name}</button>)
Readibility-wise, it's sort of an acquired taste, I'm not saying it looks better than JSX (but it's a hell of a lot readable than React.createElement, so some syntactic sugar might be put on top of it).However that's probably obvious, so: Assuming you're considering greenfield / blue sky thinking here, it's worth noting that v8 has had so much money and engineering hours sunk into it that the react-ish pseudocode probably doesn't make nearly as many allocations as a naive reading of the code might expect.
(a good friend of mine was very surprised to discover that v8's JIT is good enough that naive javascript code was basically competitive with FFI-ing out to C++ just because the node FFI layer introduced sufficient overhead that the JIT managed to catch up ... I am not a compiler wonk so please don't take this as a remotely expert pronouncement but "it is, in fact, quite difficult to overestimate v8 these days" seems to be a solid heuristic)
Who knows, if V8 manages it to turn it into a for-loop? I don't, but after a quick googling, as of 2018, it certainly didn't: https://github.com/dg92/Performance-Analysis-JS
The problem with JS is that the execution model is so nebulous, that performance advice basically boils down to - trust in Google.
but if you want to render to the DOM —and you want to use the DOM if you want to have decent accessibility, or not have to reimplement all the complex user interactions that the browsers take care of— then i think an immediate mode framework might have a great impedance mismatch with the DOM, as the latter is a retained mode GUI model