The cost of \import

49 views
Skip to first unread message

Mohammad

unread,
Dec 26, 2019, 4:14:04 AM12/26/19
to TiddlyWiki
Recently there was a discussion of global variable on github by @flibles


It was recommended to less use of global macros (those tagged with $:/tags/Macro)

So, I have started to revise some my plugins with 10s or more of global vars!

I wish to know is there any cost for \import in many tiddlers use those macros?

and what is the recommended practice here?

--Mohammad

PMario

unread,
Dec 26, 2019, 5:52:40 AM12/26/19
to TiddlyWiki
Hi,

It's nice to see, that you are interested in every aspect of TW. ...

Some "background info"

Flibbles is searching for elements in the core, that are part of the "hot path" and therefor are executed on every UI redraw. If performance can be improved there, it will positively affect everyone, without changing any "user code".

The PR you mentioned is mainly an improvement for developers using the "Flame Chart" view in the performance debugger. As a wanted "positive side effect" it seems to improve performance too.

The mechanisms involved are "low level Javascript" going down to the javascript engine.

TW internally uses JS objects to store tiddlers. So everytime a browser vendor improves performance and memory efficiency using objects we get those improvements for free.

to be continued ...

have fun!
mario

PMario

unread,
Dec 26, 2019, 6:00:22 AM12/26/19
to TiddlyWiki
On Thursday, December 26, 2019 at 10:14:04 AM UTC+1, Mohammad wrote:
...
It was recommended to less use of global macros (those tagged with $:/tags/Macro)

I did have a closer look at the PR and I can't see a recommendation to use less global macros. ...

It's true, global macros have an overhead. They set global variables which are always there, even if not used. BUT if they are needed, they don't need to be created anymore.

IMO the "convenience improvement" and its simplicity outweighs the overhead disadvantage.

-mario

PMario

unread,
Dec 26, 2019, 6:17:24 AM12/26/19
to TiddlyWiki
On Thursday, December 26, 2019 at 10:14:04 AM UTC+1, Mohammad wrote:
...
So, I have started to revise some my plugins with 10s or more of global vars!

Plugins should only define global variables / macros, that they want to expose to users. This helps to avoid "name clashes". Which I think is the main reason for this "rule"
 
I wish to know is there any cost for \import in many tiddlers use those macros?

I think it's the same, as if you use global macros. Global macros use the <$importvariables widget and \import does the same.

Using the \import pragma will marginally speed-up variable lookup, BUT on the other hand deleting and creating those variables dynamically may outweight the speed-up.

BUT without exact measurements this will be "premature optimization" which is a time wasting task.
 
and what is the recommended practice here?

As I wrote. Plugins should use global macros only if they can be used by the end-user. If they are used plugin internal, it may be worth to work with \import pragma.

But only experiments can tell, if this is possible.

have fun!
mario

Mohammad

unread,
Dec 26, 2019, 6:20:51 AM12/26/19
to TiddlyWiki
Hi Mario,
 Many thanks for clarification. There is a trade off between using global and \import vars
I think this is the rule I should follow
 

But only experiments can tell, if this is possible.


Thanks again

--Mohammad 

have fun!
mario
Reply all
Reply to author
Forward
0 new messages