cesium-native icon indicating copy to clipboard operation
cesium-native copied to clipboard

Investigate the use of cesium-native in a WebAssembly build

Open kring opened this issue 4 years ago • 4 comments

One of the potential future uses of cesium-native - though largely unexplored so far - is to compile parts of it to WebAssembly and incorporate it into CesiumJS and potentially other in-browser rendering engines.

Meanwhile, we haven't been bashful about using C++17, STL, and third-party libraries where they are helpful, all of which could potentially bloat a WebAssembly build beyond the point where it is practical to use it in this way. On top of that, some features, such as C++ exceptions, may be problematic in WebAssembly builds.

There is a tradeoff here, between moving quickly now by using the best tools at hand and not worrying excessively about the future impact on a WebAssembly build, and possibly needing to make major changes to cesium-native in the future if and when we do need to build it for WebAssembly.

For now, I don't think we'll do anything drastic, but will:

  • Avoid (but not outright forbid) the use of exceptions.
  • Select third-party libraries carefully. Don't use Boost.
  • Deal with most of the consequences later.
  • Perhaps it'd be worth spending a little time doing a WebAssembly build just to see where we stand?

CC @jtorresfabra @pjcozzi

kring avatar Dec 11 '20 00:12 kring

🙏 @kring

CC https://github.com/CesiumGS/product/issues/28

pjcozzi avatar Dec 11 '20 01:12 pjcozzi

One bullet point from the linked issue was

  • Can we make the 3D Tiles loader generic, tiny3dtiles, like https://github.com/syoyo/tinygltf

This made me wonder whether there is a smaller, more basic library hidden in the current Cesium3DTiles. Maybe something that is (roughly) only an "in-memory representation of 3D Tiles", without the infrastructure for network requests, asynchronous operations and rendering...? (The latter is where much of the compexities of threading and exceptions comes in...)

javagl avatar Dec 11 '20 14:12 javagl

I would say the sooner we start to test, the better. There are a lot of things to test/do, not only binary bloating, but also if the multithread approach works in wasm, memory consumption, compiler optimizations, no need for rtti/exceptions, image decoding intercept (as stb_image is awfully slow compared to browser image decoding), etc.

Let me know if I can be of any help, happy to try to make a build for wasm if I get some time to work on it. CC: @pjcozzi @lilleyse

jtorresfabra avatar Dec 14 '20 13:12 jtorresfabra

I changed the title to make it clearer how this is actionable.

kring avatar Apr 27 '21 08:04 kring