1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:37:35 +00:00

wasm: Map the entire input wasm file instead of using Core::File

This is a 30x (!) speedup in parsing time as we don't lose time to
Core::File's silly memmove()-into-provided-buffer stuff anymore.
This commit is contained in:
Ali Mohammad Pur 2022-10-24 04:01:40 +03:30 committed by Linus Groh
parent 8b0f05c540
commit 6b50425013

View file

@ -8,6 +8,7 @@
#include <LibCore/ArgsParser.h> #include <LibCore/ArgsParser.h>
#include <LibCore/File.h> #include <LibCore/File.h>
#include <LibCore/FileStream.h> #include <LibCore/FileStream.h>
#include <LibCore/MappedFile.h>
#include <LibLine/Editor.h> #include <LibLine/Editor.h>
#include <LibMain/Main.h> #include <LibMain/Main.h>
#include <LibWasm/AbstractMachine/AbstractMachine.h> #include <LibWasm/AbstractMachine/AbstractMachine.h>
@ -245,13 +246,13 @@ static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPoi
static Optional<Wasm::Module> parse(StringView filename) static Optional<Wasm::Module> parse(StringView filename)
{ {
auto result = Core::File::open(filename, Core::OpenMode::ReadOnly); auto result = Core::MappedFile::map(filename);
if (result.is_error()) { if (result.is_error()) {
warnln("Failed to open {}: {}", filename, result.error()); warnln("Failed to open {}: {}", filename, result.error());
return {}; return {};
} }
auto stream = Core::InputFileStream(result.release_value()); InputMemoryStream stream { ReadonlyBytes { result.value()->data(), result.value()->size() } };
auto parse_result = Wasm::Module::parse(stream); auto parse_result = Wasm::Module::parse(stream);
if (parse_result.is_error()) { if (parse_result.is_error()) {
warnln("Something went wrong, either the file is invalid, or there's a bug with LibWasm!"); warnln("Something went wrong, either the file is invalid, or there's a bug with LibWasm!");