When are filters evaluated?

Trying to understand when a filter is evaluated. Is it at wiki load time, tiddler opening time, tiddler editing time, or when?

This might be especially important for TableOfContent elements, some/all of which I presume need to be evaluated at load time and thus could affect loadtimes.

bobj

Typically filters are evaluated when the TiddlyWiki script, such as the list widget is displayed on screen. If the contents tab is closed (another selected) then it will not evaluate the filter.

However if the table of contents is displayed, if you change a tiddler, delete or rename it that is displayed in the contents the whole list is reevaluated. This is how TiddlyWiki is always up to date because changes are “transmitted” through the while wiki.

Typically the load time relates to the total size of the wiki, then what it has to do once loaded. The best first approach for performance is to add a splash screen, just so people know its loading and not a dead screen, there is much more you can do after that, but we best wait until you have a specific case so we can drill down on what it is.

  • FYI I have optimised a wiki with more than 66,000 tiddlers in the past.

You could be asking this question for another reason, to do with cases where part of a filter is not evaluated as you expect, because it is a variable or macro containing further TiddlyWiki Script, in which case you may need to $wikify it first or find another approach.

Thanks @TW_Tones . I am asking this question to improve my overall understanding of TW, which, as we have discussed between us, is essentially at the novice level.

bobj

As Tony wrote filters are evaluated when content is rendered. For the table of contents in particular only the filters for the visible elements are evaluated. …

  • So for the first level it needs to find every tiddler tagged: TableOfContents … and
  • To be able to know if the “more chevron” is needed, it also needs to evaluate the next level. eg: If there is at least 1 tiddler tagged: HelloThere … and so on.
  • Then the evaluation of the recursive macros stops.
  • The next level is only evaluated if the “more chevron” is clicked.

To speed things up internally TW keeps some indices like a database. Tags are indexed. So if you have a filter eg: [tag[HelloThere]] it only needs to scan all tiddlers once. To access this tag again, it will use the stored index, which is much faster.

-m

1 Like