[goalc] Cleaned up speedups (#3066)

Started at 349,880,038 allocations and 42s

- Switched to making `Symbol` in GOOS be a "fixed type", just a wrapper
around a `const char*` pointing to the string in the symbol table. This
is a step toward making a lot of things better, but by itself not a huge
improvement. Some things may be worse due to more temp `std::string`
allocations, but one day all these can be removed. On linux it saved
allocations (347,685,429), and saved a second or two (41 s).
- cache `#t` and `#f` in interpreter, better lookup for special
forms/builtins (hashtable of pointers instead of strings, vector for the
small special form list). Dropped time to 38s.
- special-case in quasiquote when splicing is the last thing in a list.
Allocation dropped to 340,603,082
- custom hash table for environment lookups (lexical vars). Dropped to
36s and 314,637,194
- less allocation in `read_list` 311,613,616. Time about the same.
- `let` and `let*` in Interpreter.cpp 191,988,083, time down to 28s.
This commit is contained in:
water111
2023-10-07 07:48:17 -07:00
committed by GitHub
parent af6f489657
commit 395c98db19
43 changed files with 948 additions and 549 deletions
+8 -7
View File
@@ -147,7 +147,7 @@ void parse_text_goal(const goos::Object& data,
throw std::runtime_error("invalid text version entry");
}
font = get_font_bank(ver_name.as_symbol()->name);
font = get_font_bank(ver_name.as_symbol().name_ptr);
}
else if (head.is_int()) {
@@ -278,7 +278,7 @@ GameTextVersion parse_text_only_version(const goos::Object& data) {
throw std::runtime_error("invalid text version entry");
}
font = get_font_bank(ver_name.as_symbol()->name);
font = get_font_bank(ver_name.as_symbol().name_ptr);
}
}
});
@@ -294,14 +294,14 @@ void open_text_project(const std::string& kind,
goos::Reader reader;
auto& proj = reader.read_from_file({filename}).as_pair()->cdr.as_pair()->car;
if (!proj.is_pair() || !proj.as_pair()->car.is_symbol() ||
proj.as_pair()->car.as_symbol()->name != kind) {
proj.as_pair()->car.as_symbol() != kind) {
throw std::runtime_error(fmt::format("invalid {} project", kind));
}
goos::for_each_in_list(proj.as_pair()->cdr, [&](const goos::Object& o) {
if (o.is_pair() && o.as_pair()->cdr.is_pair()) {
auto args = o.as_pair();
auto& action = args->car.as_symbol()->name;
auto& action = args->car.as_symbol();
args = args->cdr.as_pair();
if (action == "file") {
@@ -313,17 +313,18 @@ void open_text_project(const std::string& kind,
} else if (action == "file-json") {
auto& language_id = args->car.as_int();
args = args->cdr.as_pair();
auto& text_version = args->car.as_symbol()->name;
auto& text_version = args->car.as_symbol();
args = args->cdr.as_pair();
std::optional<std::string> group_name = std::nullopt;
group_name = args->car.as_string()->data;
args = args->cdr.as_pair()->car.as_pair();
goos::for_each_in_list(args->cdr.as_pair()->car, [&](const goos::Object& o) {
text_files.push_back({GameTextDefinitionFile::Format::JSON, o.as_string()->data,
(int)language_id, text_version, group_name});
(int)language_id, text_version.name_ptr, group_name});
});
} else {
throw std::runtime_error(fmt::format("unknown action {} in {} project", action, kind));
throw std::runtime_error(
fmt::format("unknown action {} in {} project", action.name_ptr, kind));
}
} else {
throw std::runtime_error(fmt::format("invalid entry in {} project", kind));