Giter VIP home page Giter VIP logo

Comments (8)

arctic-hen7 avatar arctic-hen7 commented on May 15, 2024

General Answer:
This behavior is intended (for now), and reducing bundle size has a dedicated section in the book. If you want to fully bundle for production, you should also use something like wee_alloc and apply other size optimizations. Right now, I've left those to the user because size optimizations for Wasm are greatly dependent on the trade-off an individual app wants to make between size and speed. For apps with fewer allocations, wee_alloc is a fantastic idea, and will significantly reduce bundle size. Release mode however is not intended to perform size optimizations, only speed optimizations. It takes longer because, under the hood, it runs cargo build --release and wasm-pack --release.

Specific Answer:
I see that you're already using most of these optimizations, which is great, and you should see significant size reductions from before applying them. Again though, --release mode is simply a proxy for the same flag on cargo and wasm-pack at this stage, and so it applies only the optimizations that those tools do, which, as I understand them, are mostly to do with speed rather than size.

Also, a brief side note, the <link data-trunk rel="rust" data-wasm-opt="s" /> in your index.html file won't do anything for Perseus, as it doesn't use Trunk.

from perseus.

phaleth avatar phaleth commented on May 15, 2024

Thank you @arctic-hen7 for the detailed response.

All these optimizations that I've already put in place reduce bundle.wasm file size by only ~1.5 KB.

I've looked into the docs and tried running perseus deploy and then also perseus export --release. In both cases the bundle.wasm size didn't decrease. I didn't manage to load those exports into a web browser yet.

Is it possible to run the deployed files with the perseus CLI? Bellow the output of perseus deploy says --no-run was provided and I couldn't figure out how to not provide that flag.

user@debian:~/cargo-projects/perseus-tiny$ perseus deploy
  [1/4] 🔨 Generating your app...✅
  [2/4] 🏗️  Building your app to Wasm...✅
  [3/4] 📡 Building server...✅
Not running server because `--no-run` was provided. You can run it manually by running the following executable in `.perseus/server/`.
/home/user/cargo-projects/perseus-tiny/.perseus/target/release/perseus-cli-server

Deployment complete 🚀! Your app is now available for serving in the standalone folder 'pkg'! You can run it by executing the `server` binary in that folder with the `PERSEUS_STANDALONE` environment variable set to `true`.

If I try all the originally posted optimizations with Sycamore the index-*_bg.wasm file size goes down to roughly ~1/10 of the original size, which leads me to think there could be an issue with Perseus. Also with Sycamore the command trunk serve --release works well with the originally posted optimizations.

I've found the tag <link data-trunk rel="rust" data-wasm-opt="s" /> in Sycamore's docs. Thanks for pointing out it does not apply to Perseus.

from perseus.

arctic-hen7 avatar arctic-hen7 commented on May 15, 2024

Okay, that's really weird. I got changes from 367.8kb with wee_alloc and release mode to 295.3kb after applying those optimizations, that was for the basic example. Have you applied the optimizations in .perseus/Cargo.toml as well? You need to apply them in both your own and there (admittedly, that process can be streamlined significantly).

Also, not yet. perseus deploy just creates a folder designed to be sent to a server. For what you're doing, there's no difference there from just running perseus serve --release. If you're wanting to run a deployed Perseus app that didn't use -e, you can run the server binary in the resulting pkg/ folder. If it's exported, you'll need to use something like browsersync or Vercel's serve.

from perseus.

phaleth avatar phaleth commented on May 15, 2024

Thank you @arctic-hen7. That last bit about .perseus/Cargo.toml helped.

I've updated Perseus with cargo install perseus-cli --version 0.3.0-beta.8, added the following to .perseus/Cargo.toml...

.perseus/Cargo.toml

...
[profile.release]
# Optimize for size.
opt-level = 's' # 's' or 'z' to optimize "aggressively" for size
# Enable link time optimization. Does not work with Netlify.
lto = true

... and afterwards ran perseus serve --release which got the bundle.wasm size to 265.54 KB.

image

Now that I think of how to automate the deployment, it shouldn't be a problem to append the above to the end of the .perseus/Cargo.toml with cat.

from perseus.

phaleth avatar phaleth commented on May 15, 2024

Sorry about hijacking this issue, @arctic-hen7.

Can I ask you about how to run the server binary in the ./pkg dir that you've mentioned above?

I couldn't find anything about that binary in docs. I've tried running it with a shell script and got the following error. Rust was not installed on the server.

thread 'actix-rt:worker:1' panicked at 'Couldn't get render configuration!: StoreError(NotFound { name: "./dist/render_conf.json" })', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/perseus-actix-web-0.3.0-beta.9/src/configurer.rs:72:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'actix-rt:worker:0' panicked at 'called `Result::unwrap()` on an `Err` value: PoisonError { .. }', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-3.3.2/src/server.rs:282:36

I've generated that server binary and the rest of the files as shown bellow with perseus deploy. Is it just that Rust is required to run the binary or is there also anything else?

total 10636
drwxr-xr-x 4 root root     4096 Oct 12 19:54 .
drwxr-xr-x 1 root root     4096 Oct 13 17:21 ..
drwxr-xr-x 5 root root     4096 Oct 12 19:54 dist
-rw-r--r-- 1 root root      206 Oct 12 19:54 index.html
-rwxr-xr-x 1 root root 10870520 Oct 12 19:54 server
drwxr-xr-x 2 root root     4096 Oct 12 19:54 static

from perseus.

arctic-hen7 avatar arctic-hen7 commented on May 15, 2024

No problem, but in future these questions are best asked in a discussion or on the Discord server (link in the README).

That does look like a bug, because you should be able to run the binary with a simple shell script, as long as you provide the PERSEUS_STANDALONE environment variable. If you're doing that, then this is a bug, because Rust shouldn't be required on the server. In that case, please open a new issue.

from perseus.

phaleth avatar phaleth commented on May 15, 2024

Alright. I've already tried putting PERSEUS_STANDALONE=true everywhere I could, but thanks for the hint.

Seems like I'll have to make a repro Dockerfile and describe all the steps in a new issue. That's gonna take me a while.

I'll make sure to post in discussions next time I have a question. Thanks.

from perseus.

arctic-hen7 avatar arctic-hen7 commented on May 15, 2024

Hmm, that's very odd. A new issue would be great, thanks!

from perseus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.