memos icon indicating copy to clipboard operation
memos copied to clipboard

Gomark wasm file is excessively large

Open wizcabbit opened this issue 1 year ago • 6 comments

Describe the bug

My memo's version is v0.19.1. Recently, I have noticed that the loading time is extremely long. The largest file I have identified is: /assets/gomark-Nm4xOTNx.wasm, which is 8.5MB. However, in the live demo, the same file is only 1.9MB.

What can I do to reduce the size of this file? Thank you.

Steps to reproduce

Load any page in memos

The version of Memos you're using

0.19.1

Screenshots or additional context

image

No response

wizcabbit avatar Feb 04 '24 10:02 wizcabbit

For a web App, loading every page needs to download a file that is *MB in size, it will extremely slow down its performance. I have already rollbacked my instance to v1.19.0, and look forward to the improvement.

edonyzpc avatar Feb 04 '24 15:02 edonyzpc

@boojack It's possible to reduce gomark size a little bit by building it with -trimpath -ldflags="-s -w".

The current gomark build has about 8.293,59 KiB;

  • -trimpath: 8.280,98 KiB. This removes local build system paths references, such /home/user/src/memos/related_file.go and panic stack traces will show just github.com/usememos/memos/related_file.go
  • -ldflags="-s -w": 8.023,07 KiB. This removes debug information and debug tables.
  • -trimpath -ldflags="-s -w" 8.010,43 KiB

This will save ~283 KiB. It's not much, but it's easily achievable.

Other possible solutions:

  • https://tinygo.org
  • https://github.com/WebAssembly/binaryen

By running wasm-opt gomark.wasm -o gomark-slim.wasm -Oz --enable-bulk-memory, its possible to reduce gomark to 7.120,39 KiB.

Gzip/deflate it's currently disabled in Echo, but users can enable compression using a proxy.

Quick solution for users

On Caddy, adding this directive under Memos entry will enable compression:

encode {
    zstd
    gzip
    minimum_length 1024
}

For nginx:

gzip on;
gzip_min_length 1024;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/json application/xml application/wasm application/octet-stream;

Serving gomark as it is using gzip will result in a total ~2.1 MiB transferred. image

lincolnthalles avatar Feb 05 '24 16:02 lincolnthalles

For a web App, loading every page needs to download a file that is *MB in size, it will extremely slow down its performance. I have already rollbacked my instance to v1.19.0, and look forward to the improvement.

The plug-in is transferred only once, at first page load. Your browser keeps it in cache.

Use a proxy with compression enabled to improve network performance. Check my previous comment.

lincolnthalles avatar Feb 05 '24 16:02 lincolnthalles

Add "application/wasm" to reverse proxy is useful, thanks.

wizcabbit avatar Feb 06 '24 05:02 wizcabbit

This issue is stale because it has been open 14 days with no activity.

github-actions[bot] avatar Feb 21 '24 00:02 github-actions[bot]

Please fix it as soon as possible!

zbzzh avatar Feb 26 '24 01:02 zbzzh

Reference to: https://github.com/yourselfhosted/gomark-wasm/issues/1

image

boojack avatar Mar 03 '24 16:03 boojack

mark.js仅有34k,而gomark居然有8M。

建议替换为mark.js,或给用户一个选择。 谢谢。

Doradx avatar Mar 06 '24 05:03 Doradx