[Help] performance of plugin, filters

75 views
Skip to first unread message

HC Haase

unread,
Mar 10, 2020, 6:03:39 AM3/10/20
to TiddlyWiki
When I am building my new plugin, at some point things get really slow.

Can you help me understand where I Can optimize please? I am lacking some basic understanding.

1. question
if I hide something (a filter) with the reveal widget, will it be bypassed or will it still run the filter but not show it? or is there a better  way (for speed) to toggle between things?

2.question
is there any advantage in combining filters vs. nesting them?

example:

reveal if field[x]
  list filter tag
[y] limit[1]
   stuff to show

 
/list filter
/reveal

vs

list filter field[x]tag[y] limit[1]
  stuff to show
/list


thanks

Hubert

unread,
Mar 10, 2020, 6:32:31 AM3/10/20
to TiddlyWiki
Hi HC,

1. question
if I hide something (a filter) with the reveal widget, will it be bypassed or will it still run the filter but not show it? or is there a better  way (for speed) to toggle between things?

It will be bypassed (not executed). Any code/content enclosed in a reveal widget that evaluates to False is not run and saves precious processor cycles, especially precious on mobile :)

2.question
is there any advantage in combining filters vs. nesting them?
 
Combining all your operators in one filter run is generally better than having multiple nested filters, but this depends on how you've designed your filters, i.e. how general or how specific they are. If you have two nested filters, where the outer one produces an output of 100 items and then you re-evaluate that output with your inner (embedded) filter you're essentially running it twice, which is inefficient.

For example, this is less efficient:

<$list filter="[all[tiddlers]tag[something]]">
<$list filter="[
<currentTiddler>has[field]]">

</$list>
</$list>

than this:

<$list filter="[all[tiddlers]tag[something]has[field]]">

</$list>


Please correct me if I'm wrong.

Thanks,
Hubert

HC Haase

unread,
Mar 10, 2020, 7:04:19 AM3/10/20
to TiddlyWiki
thank very much  you for your answer. This was what I suspected.


new questions.

1
is it possible to combine reveal and a filter? and will this be faster?

something like:

<$list filter="[speceficTiddler!!field[yes]<currentTiddler>has[field]]">

and 2
is there an advantage in
[all[tiddlers]tag[something]has[field]]

vs
[tag[something]has[field]]

is it an index thing?





Hubert

unread,
Mar 10, 2020, 7:11:34 AM3/10/20
to tiddl...@googlegroups.com
I'm not quite sure what you're trying to accomplish in question #1. Please post your code and someone may come up with a solution :) (I'll try my best too).

As goes for question #2, it's good practice to start building your filters by defining the fundamental category as explained here. There might be performance benefits too, but I'm not qualified to answer this part of your question.

Thanks,
Hubert

PMario

unread,
Mar 10, 2020, 7:16:31 AM3/10/20
to TiddlyWiki
Hi,
You can measure the performance of filters if you install the "Tools for exploring the internals of TW" plugin.  ... AND
Enable Performance Instrumentation in the ControlPanel: Settings tab ... THEN
SAVE
RELOAD

In the browser dev tools F12 you'll see some text: $tw.perf.log()

Enter this string into the console tab and hit enter.
You'll get a detailed overview, which filters are called, how often they are called and the time they need.

Open / Close / Open the tiddlers that contain your filters, and you'll see the impact they make.

have fun!
-mario
PS: Should I record a video about this?

HC Haase

unread,
Mar 10, 2020, 7:20:13 AM3/10/20
to TiddlyWiki


tirsdag den 10. marts 2020 kl. 12.11.34 UTC+1 skrev Hubert:
I'm not quite sure what you're trying to accomplish in question #1. Please post your code and someone may come up with a solution :) (I'll try my best too).

I am thinking if there would be a benefit to combine reveal and the filter, so instead of first a reveal and then a filter I could evaluate, in the same filter, a value in e.g. a state tiddler and then a specific tag.
 
As goes for question #2, it's good practice to start building your filters by defining the fundamental category as explained here. There might be performance benefits too, but I'm not qualified to answer this part of your question.


thanks you for your help


Hubert

unread,
Mar 10, 2020, 7:30:10 AM3/10/20
to TiddlyWiki
Yes, I understand your objectives, but I cannot answer in code if I don't have your building blocks.

Anyway, to answer your question on a high level, if your reveal widget evaluates to False, then anything it embeds (filters included) is simply not run, which does save time.

If it evaluates to True, well, then I guess your best bet would be to run performance instrumentation to see how it performs, as Mario suggested above. The same applies to your filter run, as long as you can embed the functionality of a reveal widget in your filter syntax. By running performance instrumentation you can test different solutions and boost processing time by a few hundred ms in the best of cases.

Apologies if this appears vague, I just don't want to speculate.

Many thanks,
Hubert

HC Haase

unread,
Mar 10, 2020, 8:26:14 AM3/10/20
to TiddlyWiki


tirsdag den 10. marts 2020 kl. 12.30.10 UTC+1 skrev Hubert:
Yes, I understand your objectives, but I cannot answer in code if I don't have your building blocks.

Anyway, to answer your question on a high level, if your reveal widget evaluates to False, then anything it embeds (filters included) is simply not run, which does save time.

If it evaluates to True, well, then I guess your best bet would be to run performance instrumentation to see how it performs, as Mario suggested above. The same applies to your filter run, as long as you can embed the functionality of a reveal widget in your filter syntax. By running performance instrumentation you can test different solutions and boost processing time by a few hundred ms in the best of cases.

Apologies if this appears vague, I just don't want to speculate.

Thank you. I am also trying to understand it on a high level.
as you say, when reveal widget evaluates to False it is not run, I think there are more benefit to this, that would get lost in in a filter. thanks for clarifying.


does it make sense to have a filter like below? will the all[tiddlers] do anything?

[all[tiddlers]all[current]tagging[]]
vs
[all[current]tagging[]]

Mohammad

unread,
Mar 10, 2020, 10:19:30 AM3/10/20
to TiddlyWiki


On Tuesday, March 10, 2020 at 2:46:31 PM UTC+3:30, PMario wrote:
Hi,
You can measure the performance of filters if you install the "Tools for exploring the internals of TW" plugin.  ... AND
Enable Performance Instrumentation in the ControlPanel: Settings tab ... THEN
SAVE
RELOAD

In the browser dev tools F12 you'll see some text: $tw.perf.log()

Enter this string into the console tab and hit enter.
Which string?

 
You'll get a detailed overview, which filters are called, how often they are called and the time they need.

I cannot see anything, but when when verbose is ticked I see some violation message

performance.png

 

Open / Close / Open the tiddlers that contain your filters, and you'll see the impact they make.

have fun!
-mario
PS: Should I record a video about this?

That would really appreciated! 
Reply all
Reply to author
Forward
0 new messages