-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compression #4718
base: master
Are you sure you want to change the base?
Compression #4718
Conversation
Hi @xmaysonnave apologies for the delayed response. I have some concerns about including support for compression in the core:
So, I'd like to explore how we could add the necessary hooks to make it possible to implement this compression mechanism as a plugin. The plugin could include a raw-markup tiddler that reads the compressed store area and loads the tiddlers into the |
1 - Your first remark is interesting as I made a request to go-ipfs maintainer to enhance the http header when a compressed content has been uploaded. However their consensus is to say that compression should be handled at the application level rather than the server level. It was one of my motivation to handle compression this way. 2 - The support in this PR is complete the $tw.boot.boot instantiates the $tw.util.Compress provided in the boot.js patch. 3 - Not sure if a plugin could handle the situation. It implies then that plugin will not be compressed. The approach here is the same than the current encryption mechanism. Compression occurs before any loaded tiddly logic. AFAIK only libraryModules, bootKernelPrefix and bootKernel are loaded to handle the situation. I need to say to at the moment I compress and encrypt a complete wiki with Ethereum keys. It means that extensibilty a the boot level could a real plus. My current approach is the following: 3.1 Node
ipfs-boot contain the extra logic who overload crypto and boot. 3.2 Browser 3.2.2 The first dirty solution to let it work was to copy a pached boot.js in node_modules/tiddlywiki/boot and let tiddly do the work. node and browser were tricked and used the pathed boot.js. 3.2.3 The second solution was to find a way to enhance the boot sequence without touching the boot.js. Currently I load a library modules who suppress the boot before bootKernelPrefix and bootKernel.
Then I modified tiddlywiki5.html.tid to load the real boot after the bootKernel.
I guess you got the overall idea. However I'm not completely satisfied with this approach. The Thanks |
Did you test the following workflow.
The expected result is, that there should be an Import tiddler with A and B, that should be importable. The same needs to be true, if abc.html is compressed and encrypted. The import mechanism still has to work. |
Thanks to highlight this work flow. I didn't know that it was possible. I'll take a look. |
I did read the whole thread at: ipfs/kubo#7268 and I think similar reasoning applies to the TW core. TW core already contains a jszip library. ... But I think it's not usable for your usecase. It wasn't implemented that way. You need "boot level" decompression and decryption. It seems "paco" is well maintained and reasonably small. ... but it will add a new dependency to the TW core that can't be changed anymore. ... Something that is part of the core is really hard to be removed again. Jeremy is "super picky" (in a good way) about backwards compatibility and it's almost impossible to depricate core functions. Jeremy wrote:
I'd definitely want to go that route. ... It will open up the possibility to use different compression and decompression methods, depending on the users usecase and the users taste. eg: Your tests showed, that empty-compressed is about 612kByte. That's much better than 2.3MByte, but I'd expect something like 370kByte as shown in the dev-tools if you load from https://tiddlywiki.com/empty.html, where the server does the compression. That's just an example and no offence intended. It seems, there is a possibility that you dindn't consider yet. The "external-js" configuration to load and save TWs. It may be a proper possibility for your usecase. see: https://github.com/Jermolene/TiddlyWiki5/blob/master/editions/tw5.com/tiddlywiki.info#L54 It saves a "index.html" and a "tiddlywiki5.js" file. ... The problem is, there are some bugs in the current implementation. ... But the concept should be worth a view. An empty index.html is about 80kByte So with IPFS it should be possible to get a unique and "stable" address for tiddlywiki5.js so it would be stored only once. right? index.html should be able to dynamically load this "core". It would be a "storage container", that only contains the content. This content can be encrypted before written to the ipfs store and decrypted after the core has been activated. So IPFS disc consumption would be much smaller. Since the content is encrypted client side, IPFS deduplication can't be used for content anyway. What do you think? |
@xmaysonnave Here's the discussion about the external-js with a single file wiki: #3501 ... It may not 100% solve your problem / usecase, but IMO it could be a different approach that may reduce data sent and stored at the IPFS store. I did consider it to be used with DAT- now HYPER-protocoll. Since HYPER is a copy-on-write store, which is natively versioned, it makes much sense to use TW that way. |
Thanks for your comments. I started one or two weeks ago to analyse external-js. I experimented quickly without much success. I'll revisited it. I need to find the proper balance between node generation, drag and drop plugin, libraries and manual modifications, especially at the html header level where users could tune their wiki (Meta data, etc...) external-js is interesting as he externalized exactly what I need to tune. The interesting point is that now I use my own ipfs-tiddlywiki.js with node. It open the door to tiddly node generation among chained packages. It will help to decouple the ipfs stuff from my public wiki. Let the time mature ideas and experiments... By the way my compressed empty contains my plugin. It explains the size you noticed but 700k is not bad. A few hundred ms to inflate. |
I can see, that you already digged deep into the TW build process. So I'll update my PR with some more changes. If you checkout my empty-external-js branch, you'll see the tiddlywiki.info from empty editon has a It can be built using the following command. (I'm using node version 12.18.3)
The result can be found in the tiddlywiki5-external-js.html template contains a new name for the core now: tiddlywiki.js.tiddlers.tid contains an extended filter, that will add every plugin imported in save-all-external-js.tid contains a filter now, that will remove every plugin, that is imported with drag&drop. ... So if you need those plugins in your html file you'll need to modify this filter again.... I prefere to add plugins to the external core with hope this helps. the TW code is from 5.1.18-prerelease. ... But that shouldn't matter very much. The concept is the same. |
Here's the old PR #3501 |
Motivation
IPFS with TiddlyWiki upload contents to IPFS nodes.
IPFS gateways where you retrieve contents have different setup:
1 - The ipfs.infura.io proxy server do not send compress content to client
2 - The gateway.ipfs.io proxy server send compressed content to client
3 - Uploading compressed content siply do not work as browsers do not receive the proper response header
4 - I opened a feature request to the ipfs server team to receive from the gateway the correc response header
ipfs/kubo#7268
However there is a consensus among the IPFS community who consider that compressed content sould be handled at the application level.
ipfs/notes#324
Artifacts
Implementation
The $:/core/templates/store.area.template.html handles a new compressedStoreArea
The compress widget jsonify the content and call the $tw.compress.deflate located in boot.js
The deflate function compress, convert the uint8array in base 64.
Then the compress widget encrypt if applicable.
Finally the content is jsonified.
The json signature is usefull to analyse json content (either compressed/encrypted).
IPFS with TiddlyWiki use this feature to analyse whether an attachment or an import coming from IPFS is encrypted (compression is not implemented yet)
Open Questions
The hook "th-boot-tiddlers-loaded" is called during the $tw.boot.startup.
A mechanism to enhance the $tw.boot.boot function could be interresting if plugin developers wish to use another encryption/compression strategy without modifying the core sequence.
It probably means to have a special html container who will load the minimal javascript logic who could overload the compress/encryption mechanism with other strategies.
Encrypting a base64 content could cause issues and I faced this problem with attachments.
However I've been unable to reproduce this issue at the boot sequence.
I tried various strategies :
Results
This PR is able to generate a few samples:
Some benchmarking :
2 - on my mobile Redmi note 7 pro
Remarks
3.1 _license_uri, the url to the license
3.2 _project_uri, the project url
3.3 _source_uri, where the library has been downloaded with its version