A KISS Template to Calculate the Size of Tiddlers and Plugins

There are some codes to calculate the size of tiddlers like the plugin size from @telmiger or the solution by @EricShulman or the code is displayed in edit mode from @linonetwo. I am sure there are other solutions out there I have not seen.

One simple and close to real size is the below WIkitext

  • Create a tiddler, and tag it with $:/tags/ViewTemplate/Subtitle
  • Put the below WikText inside body (text field and save)
  • Open any tiddler and see the size in kB at the bottom of tiddler.
Size of tiddler:  <$text text={{{
[<currentTiddler>fields[]] :map[<..currentTiddler>get<currentTiddler>length[]else[0]]
[<currentTiddler>fields[]length[]]
:and[sum[]divide[1024]] kB :and[join[ ]]
}}}/>
  • Please share if you have a simpler or more complete solution
  • Please revise the above code to improve the precision of calculated value
4 Likes

See https://tiddlytools.com/#TiddlyTools%2FEditTemplates%2FSize

The tiddler is tagged with $:/tags/EditTemplate and has a list-after field set to $:/core/ui/EditTemplate/controls, so that the output appears below the "Draft of ..." title while editing a tiddler. The output shows a summary with the total lines/words/bytes for the current tiddler, followed by a down-arrow. Clicking the summary opens a popup containing a table that shows the lines/words/bytes for each field.

5 Likes

That’s pretty awesome.

If you want storage accuracy, though, 1KB = 1024 bytes, 1 byte per character.

But that’s just being finicky.

Thank you! The code is corected!

Very nice! Thank you, Eric.

As a result of @Mohammad’s OP, I realized that I wasn’t including the size of the field NAMES in my size calculations! In response, I’ve updated several places where this type of calculation was being done. The following tiddlers have changed to more accurately reflect total tiddler sizes:

TiddlyTools/Search/Filters,
TiddlyTools/Catalog/Statistics,
TiddlyTools/EditTemplates/Size,
TiddlyTools/Catalog/RecentChanges

-e

2 Likes

How to revise the code for only 2 decimal places are displayed? (e.g. 2.33 KB)

edit: hey I just figured out by searching decimal in the main site!

this is what I did:

Size of tiddler: <$text text={{{
[<currentTiddler>fields[]] :map[<..currentTiddler>get<currentTiddler>length[ ]else[0]]
[<currentTiddler>fields[]length[]]
:and[sum[]divide[1024]fixed[2]] kB :and[join[ ]]
}}}/>

I just added the fixed[2] in the last line and it works.

I also change the tag to $:/tags/ViewTemplate/Subtitle so that it displays in subtitle of each tiddler

2 Likes