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
Notes: sideshowbarker 2024-07-17 05:09:37 +09:00

View file

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