project-mahiwa / mahiwa-frontend-go

mahiwaのGo言語向けフロントエンド
https://pkg.go.dev/github.com/project-mahiwa/mahiwa-frontend-go
MIT License
0 stars 0 forks source link

[🛠️Refactor]:メモリが少ないマイコンでも動くようにビルドオプションを設定する #13

Closed usuyuki closed 11 months ago

usuyuki commented 11 months ago

🛠️ 概要

なぜ必要

備考

usuyuki commented 11 months ago

wasm3側でなく,マイコンにヒープメモリ増やしてといったほうがよいかも? https://qiita.com/nizuki926/items/216bf767b8f0d1dd5dbf

usuyuki commented 11 months ago

https://docs.platformio.org/en/latest/faq/program-memory-usage.html

PROGRAM (Flash) = .text + .data

DATA (RAM) = .bss + .data

なるほど?

usuyuki commented 11 months ago

マイコンにより違うので,https://github.com/project-mahiwa/mahiwa-backend/issues/31

usuyuki commented 11 months ago

逆にwasmで線形メモリを使わずどうにかできるか? →文字列を含まないようにしてもmemory 2とる.多分wasiがそういう仕組み.

printしてなくてもpanicの文などがwasm内に書き込まれている.

usuyuki commented 11 months ago

https://github.com/wasm3/wasm3/blob/main/docs/Hardware.md#limited-support

The following devices can run Wasm3, however they cannot afford to allocate even a single Linear Memory page (64KB). This means memoryLimit should be set to the actual amount of RAM available, and that in turn usually breaks the allocator of the hosted Wasm application (which still assumes the page is 64KB and performs OOB access).

なのでwasm3でどうこうするのでなく,そもそもwasmが生成される時点でやる必要がありそう.

usuyuki commented 11 months ago

https://github.com/tinygo-org/tinygo/issues/2108 なるほど

usuyuki commented 11 months ago

wasm3側ではどうにもできないので,frontend-go側にissueを移動する.

usuyuki commented 11 months ago

理由があってmemory 2にしているものを勝手に変えてもいいの?

usuyuki commented 11 months ago

https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/pico_platform/include/pico/platform.h#L31

PICOのヒープはデフォが0x800=2048byte

usuyuki commented 11 months ago
wasm2wat tinygo-wasi-memory-limit.wasm -o tinygo-wasi-memory-limit.wat

でtarget.json

{
    "inherits": [ "wasi" ],
    "ldflags": [
        "--initial-memory=65536",
        "--max-memory=65536",
        "-zstack-size=2048"
    ]
}

で動かすと

memory 1 1になった.

小さくできるならなんで最初から小さくないの?