Tinderbox Forum

TBX TIP: Consider using attributes to cache action code result to optimize TBX performance

If you’re going to use a lot of display expressions (see Action Code Example: Update a note’s display expression with the count of its children or descendants, especially in a file with thousands of notes, I recommend that you create a $DisplayExpressionCache user attribute. Your use of this attribute is an important step towards optimizing the performance of your Tinderbox file. All you need to do is create the attribute, create your action code, and then set your $DisplayExpression to $DisplaedAttributeCache.

Why? Every time Tinderbox refreshes a view it runs the associated action code assigned to each and every note displayed in the view. So, if you put your action code directly into the $DisplayExpression attribute of a note, and if you have hundreds or thousands of notes, every time Tinderbox refreshes its view it will run the code for every note. Running the code takes processing power, i.e. time, and in this context taking up the extra processing power is unnecessary. It is more efficient for Tinderbox to run your display expression action code as an Edict, i.e. have the Edict do the work and update a note’s $DisplayExpressionCache attribute, and then have the $DisplayExpression attribute value pull its value from $DisplayExpressionCache. By doing this, when Tinderbox goes to refresh a view it is not executing action code and taking up precious processing power each time it refreshes a note, rather it is simply pulling in a value from the note’s $DisplayExpressionCache, which takes little effort, aka processing power.

I think this is chiefly useful for (a) complex display expressions that do lots of work, and (b) really big documents.

1 Like