Global Macro or Local

120 views
Skip to first unread message

Mohammad

unread,
Apr 5, 2019, 4:15:59 AM4/5/19
to TiddlyWiki
I get used to add $:/tags/Macro to each tiddler contains macro. This way I can simply use the macros whenever I wish!

Recently, I noted this may cause a performance issue! It seems all those tiddlers are loaded when TW is started!

I realized the recent version of TW let me use \import pargma to load them on demand!

I like to know your opinion on this! Which method do you recommend

  1. Tag all macro tiddler with $:/tags/Macro! The easy way and simple use
  2. Import macro on a tiddler you wish to use that macro, need a little more elaboration, ... BUT seems this has a positive performance impact!

--Mohammad

TonyM

unread,
Apr 5, 2019, 7:26:51 PM4/5/19
to TiddlyWiki
mohammad

I tend to use global macros even in complex wikis without any impact noted yet. You can use dumpvariables to gauge how large this impact is.

We can use import variables to include macros that are not global.

Depending on how macros are written the size of the included code on every tiddler can be quite different as I understand it. Using conditions in templates tagged for the view template or the reveal widget will change what is included with the rendered tiddler.

Because of these various factors I tend to write with a view to being brief and minimalist with conditions but let myself use globals whenever the use is broad.

Regards
tony

Mal

unread,
Apr 6, 2019, 2:31:45 AM4/6/19
to TiddlyWiki
The other issue is the potential for namespace collisions when using $:/tags/Macro. In a tiddler with this tag, every macro is available globally, so you need to be careful to choose unique names. Importing macros avoids this problem.

Mal

TonyM

unread,
Apr 6, 2019, 3:26:18 AM4/6/19
to TiddlyWiki
mal

Not avoiding duplicate names is the problem from which importvariables is a work around.

Tony

Jeremy Ruston

unread,
Apr 6, 2019, 4:01:16 AM4/6/19
to tiddl...@googlegroups.com
Hi Tony

> Not avoiding duplicate names is the problem from which importvariables is a work around.

The purpose of importvariables is to allow macros to be local to a particular tiddler, giving much more flexibility in their reuse. Variables in TW are much like variables in an ordinary programming language in that we can reuse the same variable names in separate functions/tiddlers without them clashing.

Best wishes

Jeremy

>
> Tony
>
> --
> You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
> To post to this group, send email to tiddl...@googlegroups.com.
> Visit this group at https://groups.google.com/group/tiddlywiki.
> To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/a0563edb-cc4c-44c2-a6b4-b5d060deb319%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Mohammad

unread,
Apr 6, 2019, 4:36:45 AM4/6/19
to TiddlyWiki
Dear all,
Thank you for your inputs.

 I understood, the encourage is NOT to use global variable and seems performance is here not a big issue!

--Mohammad


On Saturday, April 6, 2019 at 12:31:16 PM UTC+4:30, Jeremy Ruston wrote:
Hi Tony

> Not avoiding duplicate names is the problem from which importvariables is a work around.

The purpose of importvariables is to allow macros to be local to a particular tiddler, giving much more flexibility in their reuse. Variables in TW are much like variables in an ordinary programming language in that we can reuse the same variable names in separate functions/tiddlers without them clashing.

Best wishes

Jeremy

>
> Tony
>
> --
> You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to tiddl...@googlegroups.com.

Jeremy Ruston

unread,
Apr 6, 2019, 4:41:55 AM4/6/19
to tiddl...@googlegroups.com
Hi Mohammad

 I understood, the encourage is NOT to use global variable and seems performance is here not a big issue!

There is minimal processing at the point where a macro is defined; we just save the text of the macro. It's only when the macro is used that its content is parsed and rendered.

Best wishes

Jeremy.


--Mohammad

On Saturday, April 6, 2019 at 12:31:16 PM UTC+4:30, Jeremy Ruston wrote:
Hi Tony

> Not avoiding duplicate names is the problem from which importvariables is a work around.

The purpose of importvariables is to allow macros to be local to a particular tiddler, giving much more flexibility in their reuse. Variables in TW are much like variables in an ordinary programming language in that we can reuse the same variable names in separate functions/tiddlers without them clashing.

Best wishes

Jeremy

>
> Tony
>
> --
> You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to tiddl...@googlegroups.com.
> To post to this group, send email to tiddl...@googlegroups.com.
> Visit this group at https://groups.google.com/group/tiddlywiki.
> To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/a0563edb-cc4c-44c2-a6b4-b5d060deb319%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

Mohammad

unread,
Apr 7, 2019, 12:36:29 AM4/7/19
to TiddlyWiki
Thanks Jeremy!

Added to TW-Scripts.
Hi Mohammad

Reply all
Reply to author
Forward
0 new messages