Skip to content

Commit 44be7b1

Browse files
authored
Chore: Remove the initEngine methods, and update Warm test. (#459)
* Remove the init*engine methods from runtimes, and update warm() test. Signed-off-by: Rachel Green <[email protected]>
1 parent 14fa83a commit 44be7b1

File tree

8 files changed

+14
-37
lines changed

8 files changed

+14
-37
lines changed

include/proxy-wasm/v8.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
namespace proxy_wasm {
2323

24-
bool initV8Engine();
2524
std::unique_ptr<WasmVm> createV8Vm();
2625

2726
} // namespace proxy_wasm

include/proxy-wasm/wamr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
namespace proxy_wasm {
2323

24-
bool initWamrEngine();
2524
std::unique_ptr<WasmVm> createWamrVm();
2625

2726
} // namespace proxy_wasm

include/proxy-wasm/wasmtime.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
namespace proxy_wasm {
2020

21-
bool initWasmtimeEngine();
2221
std::unique_ptr<WasmVm> createWasmtimeVm();
2322

2423
} // namespace proxy_wasm

src/v8/v8.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,6 @@ std::string V8::getFailMessage(std::string_view function_name, wasm::own<wasm::T
759759

760760
} // namespace v8
761761

762-
bool initV8Engine() { return v8::engine() != nullptr; }
763-
764762
std::unique_ptr<WasmVm> createV8Vm() { return std::make_unique<v8::V8>(); }
765763

766764
} // namespace proxy_wasm

src/wamr/wamr.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,6 @@ void Wamr::warm() { initStore(); }
713713

714714
} // namespace wamr
715715

716-
bool initWamrEngine() { return wamr::engine() != nullptr; }
717-
718716
std::unique_ptr<WasmVm> createWamrVm() { return std::make_unique<wamr::Wamr>(); }
719717

720718
} // namespace proxy_wasm

src/wasmedge/wasmedge.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@ using HostModuleDataPtr = std::unique_ptr<HostModuleData>;
225225
class WasmEdge : public WasmVm {
226226
public:
227227
WasmEdge() {
228-
loader_ = WasmEdge_LoaderCreate(nullptr);
229-
validator_ = WasmEdge_ValidatorCreate(nullptr);
230-
executor_ = WasmEdge_ExecutorCreate(nullptr, nullptr);
231228
store_ = nullptr;
232229
ast_module_ = nullptr;
233230
module_ = nullptr;
@@ -305,6 +302,7 @@ class WasmEdge : public WasmVm {
305302

306303
bool WasmEdge::load(std::string_view bytecode, std::string_view /*precompiled*/,
307304
const std::unordered_map<uint32_t, std::string> & /*function_names*/) {
305+
initStore();
308306
WasmEdge_ASTModuleContext *mod = nullptr;
309307
WasmEdge_Result res = WasmEdge_LoaderParseFromBuffer(
310308
loader_.get(), &mod, reinterpret_cast<const uint8_t *>(bytecode.data()), bytecode.size());
@@ -324,6 +322,9 @@ void WasmEdge::initStore() {
324322
if (store_ != nullptr) {
325323
return;
326324
}
325+
loader_ = WasmEdge_LoaderCreate(nullptr);
326+
validator_ = WasmEdge_ValidatorCreate(nullptr);
327+
executor_ = WasmEdge_ExecutorCreate(nullptr, nullptr);
327328
store_ = WasmEdge_StoreCreate();
328329
}
329330

src/wasmtime/wasmtime.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,6 @@ void Wasmtime::warm() { initStore(); }
710710

711711
} // namespace wasmtime
712712

713-
bool initWasmtimeEngine() { return wasmtime::engine() != nullptr; }
714-
715713
std::unique_ptr<WasmVm> createWasmtimeVm() { return std::make_unique<wasmtime::Wasmtime>(); }
716714

717715
} // namespace proxy_wasm

test/wasm_vm_test.cc

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,17 @@ INSTANTIATE_TEST_SUITE_P(WasmEngines, TestVm, testing::ValuesIn(getWasmEngines()
3131
});
3232

3333
TEST_P(TestVm, Init) {
34-
std::chrono::time_point<std::chrono::steady_clock> time2;
35-
3634
auto time1 = std::chrono::steady_clock::now();
37-
if (engine_ == "v8") {
38-
#if defined(PROXY_WASM_HOST_ENGINE_V8)
39-
EXPECT_TRUE(proxy_wasm::initV8Engine());
40-
time2 = std::chrono::steady_clock::now();
41-
EXPECT_TRUE(proxy_wasm::initV8Engine());
42-
#endif
43-
} else if (engine_ == "wamr") {
44-
#if defined(PROXY_WASM_HOST_ENGINE_WAMR)
45-
EXPECT_TRUE(proxy_wasm::initWamrEngine());
46-
time2 = std::chrono::steady_clock::now();
47-
EXPECT_TRUE(proxy_wasm::initWamrEngine());
48-
#endif
49-
} else if (engine_ == "wasmtime") {
50-
#if defined(PROXY_WASM_HOST_ENGINE_WASMTIME)
51-
EXPECT_TRUE(proxy_wasm::initWasmtimeEngine());
52-
time2 = std::chrono::steady_clock::now();
53-
EXPECT_TRUE(proxy_wasm::initWasmtimeEngine());
54-
#endif
55-
} else {
56-
return;
57-
}
35+
vm_->warm();
36+
auto time2 = std::chrono::steady_clock::now();
37+
vm_->warm();
5838
auto time3 = std::chrono::steady_clock::now();
5939

6040
auto cold = std::chrono::duration_cast<std::chrono::nanoseconds>(time2 - time1).count();
6141
auto warm = std::chrono::duration_cast<std::chrono::nanoseconds>(time3 - time2).count();
6242

63-
std::cout << "\"cold\" engine time: " << cold << "ns" << std::endl;
64-
std::cout << "\"warm\" engine time: " << warm << "ns" << std::endl;
43+
std::cout << "[" << engine_ << "] \"cold\" engine time: " << cold << "ns" << std::endl;
44+
std::cout << "[" << engine_ << "] \"warm\" engine time: " << warm << "ns" << std::endl;
6545

6646
// Default warm time in nanoseconds.
6747
int warm_time_ns_limit = 10000;
@@ -75,6 +55,11 @@ TEST_P(TestVm, Init) {
7555
EXPECT_LE(warm, warm_time_ns_limit);
7656

7757
// Verify that getting a "warm" engine takes at least 50x less time than getting a "cold" one.
58+
// We skip NullVM because warm() is a noop.
59+
if (engine_ == "null") {
60+
std::cout << "Skipping warm() performance assertions for NullVM." << std::endl;
61+
return;
62+
}
7863
EXPECT_LE(warm * 50, cold);
7964
}
8065

0 commit comments

Comments
 (0)