Replies: 2 comments 6 replies
-
Why data-tiddlers are sub-optimal.A Now let's say test-1 is a data tiddler. It would look like this:
B
So worst case if the index we want is the last index in the tiddler we waste a lot of CPU cycles. ... To parse data-tiddler indexes and present them in a decent way in wikitext needs definitely more code then accessing and displaying a core field. C If it would look like this:
Access would be fast. ... |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot @pmario for this fantastic presentation. thanks again |
Beta Was this translation helpful? Give feedback.
-
Some TW internals.
The following description of the tiddler store is a bit simplified for explanation reasons.
0
In javascript almost everything is an Object {}, that's why the browser javascript engine is highly optimized to work with them. Access to object keys is fast! ... Really fast!
1
A simple Object can look like this:
{title: "HelloThere"}
... We can say:title
is a key andHelloThere
is a value2
So we have an Object that contains a key : value pair.
3
But this doesn't make a tiddler. ... We need
tags
,created
,creator
,modified
,modifier
and so on.4
So the tiddler-like Object looks more like this:
As you can see, there are some values, that are strings.
text, creator, title
... AND ...There are also some other elements:
created and tags
that are different.created
is a Date andtags
is an Array [].5
So we have 1 "tiddler-like" object now. ... But 1 tiddler doesn't make a store. right?
We need more objects to store several tiddlers. ...
Which could looks like this: An
Array[ of tiddler-Object {} ]
6
The problem with arrays is: Accessing them will need a loop. So searching for eg:
title: "test-1"
will need to:title
if it is "text-1" ... notitle
... and so on ... and so on. ...That's a lot of work. ... A lot of CPU cycles. ... BUT ... We want it fast. ... Really fast. ... Remember step 0?? ... We need a
tiddlers object{}
, where the key is the tiddler title. Like so:That's an Object-store. ...
So the tiddler-title is the key and the
tiddler Object {}
is the value. .. .YES ... Objects can be nested!To retrieve
test-1
is as simple as accessingtiddlers["test-1"]
now.tiddlers
is not an array it's an object. ... Remember step 0 Accessing object keys is fast. ...That's the main reason why tiddler titles have to be unique. ... Object keys have to be unique, to have the fastest access possible!
So a function similar to:
will return
All of this can be done by the browser javascript engine with max speed.
Beta Was this translation helpful? Give feedback.
All reactions