konsoletyper / teavm

Compiles Java bytecode to JavaScript, WebAssembly and C
https://teavm.org
Apache License 2.0
2.55k stars 261 forks source link

Add an option to choose FS implementation for JS BE #821

Open konsoletyper opened 8 months ago

konsoletyper commented 8 months ago

Current implementation of FS in JS keeps everything in memory. In real world cases users may want to keep their files in persistent storage. Filesystem support in TeaVM already relies on interface, which has implementations (in-memory and WASI), so it's only a matter of providing extra implementations as well as a way to pass compiler the name of desired implementation (TeaVM properties can be used for example).

It's reasonable to have two additional implementations for JS BE:

  1. Asynchronous, which keeps everything in memory, but eventually flushes in-memory changes into persistent storage (i.e. IndexedDB). This is necessary, since IndexedDB itself asynchronous and if we want to keep good performance by preventing turning Java methods into state machine, we can use this implementation. This implementation would also require that main method starts asynchronously to make sure that all data read from IndexedDB into memory.
  2. Synchronous, which never keeps data in memory, and all reads/writes all data 'synchronously', from Java's standpoint.