bugra9 / gdal3.js

Convert raster and vector geospatial data to various formats and coordinate systems entirely in the browser.
https://gdal3.js.org
GNU Lesser General Public License v2.1
314 stars 48 forks source link

compiling with -Oz flag #85

Open kbhalerao opened 4 days ago

kbhalerao commented 4 days ago

Thank you for this wonderful project. I wanted to include this library in a SvelteKit project to be hosted on CloudFlare Pages, and to run the GDAL library as a Worker. The non-Worker version, using the CDN works fine as shown in the docs.

CloudFlare Pages has a limit of 25MB for uploaded assets.

To reduce the file size, I was able to successfully compile this package using the -Ozflag, as opposed to the current -O3 setting. This brings the compiled size for the .wasm file from ~28MB to ~22MB, just under the CloudFlare limits, and it seems to work normally.

I manually included the package files in my project's assets folder and linked them via the paths option in initGdalJS()

Is there any way to host a smaller-sized variant of the package under this project on the CDN or in NPM, to make this directly usable for CloudFlare Pages users?

Is there another way to reduce file size by either splitting the large wasm file into multiple, or by configuring GDAL to include only a few common drivers?

bugra9 commented 1 day ago

Hi @kbhalerao,

Thanks for the kind words! I'm glad gdal3.js is working well in your SvelteKit project.

I’ve looked into dynamic linking and module splitting, but they aren’t really applicable for WebAssembly right now. Creating different builds with specific driver combinations is a good workaround.

Another option is compression. Both the .wasm and data files can be compressed and decompressed using DecompressionStream during initialization. This brings the total size down to around 11.3 MB (compressed .wasm is 9.2 MB, and data is 2.1 MB). Browsers and servers usually handle this automatically to reduce network traffic, but I could provide compressed versions on NPM/CDN to help with the file size limits.