Is this $list-based macro an efficient solution? Or more generally: Are there any general tips for improving efficiency?

This macro works perfectly; however it is used so frequently in many tiddler in the story river that I am now consciously questioning its efficiency.

\define myMacro(var)
<$list filter="[<_var_>!is[blank]]">
  <$button>myButton</$button>
</$list>
\end

<<myMacro>> => there should be no button.

<<myMacro param>> => the button appears and reveals the content.

Is that an elegant solution?

I have some concerns because it is said that the listWidget consumes a lot of processing power, so there might be better approaches, perhaps using the revealWidget. I often wonder whether there are more efficient ways to solve a given task. For example, I was “surprised” by a comment from Eric Shulman, who gave me the following tip, which has helped me write much more efficient macros that no longer waste processing power and slow down input.

Since then, I have been wondering whether there are more such “traps” – or rather, useful tips – for programming TiddlyWiki-Script.

Best
g.eron

In general, the $list widget itself does not “consume a lot of processing power”.

My “costly $list widget evaluation” comment in Delete all user define fields, was specifically referring to the nested $list widgets used in the delete-fields() procedure which checks all non-system fields in all non-system, non-shadow tiddlers.

Your current use-case (i.e., filter="[<__var__>!is[blank]]") is actually very low-cost, since it is simply checking to see if a single specified variable is blank.

So… don’t worry (be happy!)

-e

1 Like

Ah, OK, that makes perfect sense, thank you very much for the clarification.

Your tip about putting the procedure call into the actions= parameter of $button has made a big difference for my wiki – it allowed me to make it feel much more responsive in use. I don’t think I would have come up with that on my own.

I realise it’s hard to give more general advice without a specific use case. But your tip has had a big impact and if others have had similar “aha moments”, I’m always happy to read about them.

best
g.eron