excalidraw-jetbrains-plugin icon indicating copy to clipboard operation
excalidraw-jetbrains-plugin copied to clipboard

Rework Plugin / JCef exchange of file payload

Open bric3 opened this issue 2 years ago • 0 comments

Currently file are exchanged as base64 strings in a payload run by CefFrame::executeJavaScript, this is not optimal for several reasons :

  • Base 64 encoding increase the size by ~33 % (not even accounting the line breaks)
  • Given excalidraw can embed pictures, the payload can be even bigger.
  • Big strings (backed by an array) will cause on G1GC (the default on IJ at this time) to create humongous region if the string is bigger than half the region size (which by default depends on the total Java heap).
    • Java heap of 4 GiB usually have 2 MiB regions, so HO are created when content is over 1 MiB,
    • Java heap of 2 GiB usually have 1 Mib regions, so HO are created when content is over 512 KiB.

In order to improve that aspects there are multiple options

  1. Use "the server" that would be able to server and receive files
  2. Avoid facing the problem by changing the encode to uuEncoding. (Not a lot of implementation out there : https://github.com/biagioT/java-uudecoder)
  3. Explore approaches using browser file system APIs (may not be be supported by Cef)
    • https://developer.mozilla.org/en-US/docs/Web/API/FileSystem
    • https://developer.chrome.com/docs/apps/reference/fileSystem

bric3 avatar Jan 12 '24 13:01 bric3