Skip to content
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/v8/v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@

#include "include/proxy-wasm/limits.h"

#include "absl/strings/str_format.h"
#include "include/v8-initialization.h"
#include "include/v8-version.h"
#include "include/v8.h"
#include "src/flags/flags.h"
#include "src/wasm/c-api.h"
#include "wasm-api/wasm.hh"

Expand All @@ -42,10 +43,12 @@ wasm::Engine *engine() {
static wasm::own<wasm::Engine> engine;

std::call_once(init, []() {
::v8::internal::v8_flags.liftoff = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why? It was written years ago, but at the time loading Wasm module wouldn't complete before all compilation phases completed, so Liftoff compilation was wasteful. Is that not the case anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the callout on this. I discussed with Matt and we do want to keep this disabled - Updated.

Copy link
Contributor

@mpwarres mpwarres Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping it SGTM, but I think it would be helpful to add a comment that provides some context on why we set it. Internal bug b/278233034 contains some pointers to past discussions. I'd suggest something like: "Disable Liftoff compiler to force optimized JIT up-front."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this is based on tests from years ago, but TurboFan was always blocking loading of Wasm modules, and this flag doesn't affect that. What it does is that it skips Liftoff compilation that would be discarded in favor of TurboFan anyway... It would be good to verify that's still the case, though.

There are some docs for V8 here: https://v8.dev/docs/wasm-compilation-pipeline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want Turbofan to block on loading of Wasm modules, right? Thanks for the docs link, it aligns with discussion above: --no-liftoff sets the "TurboFan only" mode. If liftoff is enabled, calls can immediately use the compiled code, and then re-compilation with TurboFan is triggered in the background only after a certain threshold of calls.

::v8::internal::v8_flags.wasm_max_mem_pages =
PROXY_WASM_HOST_MAX_WASM_MEMORY_SIZE_BYTES / PROXY_WASM_HOST_WASM_MEMORY_PAGE_SIZE_BYTES;
std::string args = absl::StrFormat("--wasm_max_mem_pages=%u --no-liftoff",
PROXY_WASM_HOST_MAX_WASM_MEMORY_SIZE_BYTES /
PROXY_WASM_HOST_WASM_MEMORY_PAGE_SIZE_BYTES);
::v8::V8::SetFlagsFromString(args.c_str(), args.size());
::v8::V8::EnableWebAssemblyTrapHandler(true);

engine = wasm::Engine::make();
});

Expand Down
Loading