Replies: 4 comments 6 replies
-
I think the main problem with "core" aliases is performance. Accessing a tiddler by name is only 1 memory "lookup" ... The internal tiddler store is an object that is defined like so:
As you can see, the tiddler title eg: "tiddlerB" is there 2 times. ... This makes it easy and extremely fast to "lookup a tiddler by name"
Since accessing object elements is highly optimized by the js-compiler, accessing a tiddler by name like this is probably the fastest "memory" access that we can create with javascript. That's also the main reason, why tiddler titles have to be unique, because object element names have to be unique in JS. From the structure above, you can see, that adding an alias field to the There are 3 lookup indexes, that are part of the core atm: (all of them need additional memory)
So we "trade" memory consumption for lookup performance. But even if we have an index we still need 2 or more lookups instead of 1 to get a tiddler object.
So we end up with 2 memory access actions, in a program code that is very low level and executed very often. Adding extra code at this level, can make a big difference. ... The same is true for removing code. Since a TW page is built with "tagged lists" of templates, the core already has a lot to do, to build the lists. We really need to take care, if we add extra code for looking up template aliases. ... hope that helps to make the underlying mechanisms clearer. I think it's not that we don't want to have aliases. I think it's the additional complexity that will be needed to make it performant and consistent. |
Beta Was this translation helpful? Give feedback.
-
That's right ... but ... Having no explicit tiddler name is the problem. As I wrote, we have to create a lookup index at startup or by 1st request. Then every time we need an "alias-template" that is called by the alias name we have 2 lookups instead of 1. ... That does double the CPU cycles needed to access the tiddler content. Transcluding tiddler content is 1 of the widgets, that is used a lot. So adding an extra It's really hard to describe. All of this goes down to the underlying js-code. ... Every TW widgets inherits the code from here: https://github.com/Jermolene/TiddlyWiki5/blob/master/core/modules/widgets/widget.js .. Then the widgets "overwrite" functions, that are different to widget.js The code we are talking about can be found here: https://github.com/Jermolene/TiddlyWiki5/blob/master/core/modules/widgets/transclude.js The code that accesses the tiddler store for transclusions is: As you can see, none of those elements has an idea about an alias-name. ... It's not that simple to find the right position, where to implement the new alias-functions. It has to be generic enough, to work with every edge case, where transclsions can happen and it should be performant. |
Beta Was this translation helpful? Give feedback.
-
The first thing to note is that people can already make constructions like Secondly, @twMat's intuition is correct: supporting aliases in a particular situation such as transclusion templates is a much more limited proposition than full fledged support for generic aliases, and thus easier and less risky to implement. I would be interested in adding support for short template names, but I wouldn't approach it in quite this way. Instead, I'd favour an alternate transclusion syntax that makes it explicit that a short name is being specified. It would then be prefixed with |
Beta Was this translation helpful? Give feedback.
-
I could think about a call like this: Calling it without a tiddlerName would look like: I wouldn't limit it to just a thought. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
There is currently no alias feature in the core, but there are recurring requests for it.
The following proposal concerns the particular case of using aliases in templates. I'm thinking that the restricted environment for templates, e.g inside a
{{{
filtered transclusion}}}
, might simplify implementing a special, yet very useful, use case for aliases. (And, who knows, maybe it could serve as a bridge for a general implementation of aliases.)If I understand it right, a main reason for not including "end user templates" in the core is because the end users assumed "friendly titles requirement" conflict with the shadow tid naming conventions. Still, it would be very useful to be able to do e.g:
{{{ should-not-be-linkified || textify }}}
i.e to apply a core defined template via a user friendly name - an alias - like "textify".
Regardless of implementation, there is need to match the aliases to tiddlers. Here are two ideas for this, a manual mapping and a special marker to flag to the system that a string is an alias:
Manual mapping - declarations and precedence
For declaring an alias, there can be two parallel methods - actually somewhat comparable to how items can appear in lists by either being included from some attribute such as a tag, or from a local
list-before
field:alias
field in the tiddler.Here comes the special part: If there is a real tiddler titled like the alias then this would take precedence! (Compare this to how real tids overwrite shadow tids.) The order of precedence (from stronger to weaker) would be
Special marker
To reduce the risk of someone unknowingly titling a tiddler like an alias, an alias call could require some marker, for example a prefixing
...
or evenalias:
(must still be simple enough to type). Such a prefix could also signify that a certain fallback path is to be used, e.g$:/core/Template/
. I guess the precedence could be anywhere in positions 2, 3 or 4.Such a
$:/core/Template/
prefix would make for yet an "entry" for creating custom templates that are accessible via aliases, i.e just create a tiddler titled$:/core/Template/mytemplate
, andmytemplate
is enough to invoke the template. And it would be simple enough to share templates with one another and add new templates to the core.Thoughs?
Beta Was this translation helpful? Give feedback.
All reactions