mirror of
https://github.com/open-goal/jak-project
synced 2026-08-21 23:00:45 -04:00
[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:
+7
-32
@@ -441,31 +441,6 @@ TEST(GoosBuiltins, Type) {
|
||||
EXPECT_EQ(e(i, "(type? 'environment '())"), "#f");
|
||||
}
|
||||
|
||||
/*!
|
||||
* Confirm that the global and goos env variables appear
|
||||
*/
|
||||
TEST(GoosEval, GlobalAndGoalEnv) {
|
||||
Interpreter i;
|
||||
Object goal_env, goos_env;
|
||||
EXPECT_TRUE(i.get_global_variable_by_name("*global-env*", &goos_env));
|
||||
EXPECT_TRUE(i.get_global_variable_by_name("*goal-env*", &goal_env));
|
||||
|
||||
auto& goal_vars = goal_env.as_env()->vars;
|
||||
auto& goos_vars = goos_env.as_env()->vars;
|
||||
|
||||
EXPECT_TRUE(goal_vars.find(i.intern("*global-env*").as_symbol()) != goal_vars.end());
|
||||
EXPECT_TRUE(goal_vars.find(i.intern("*goal-env*").as_symbol()) != goal_vars.end());
|
||||
EXPECT_TRUE(goos_vars.find(i.intern("*global-env*").as_symbol()) != goos_vars.end());
|
||||
EXPECT_TRUE(goos_vars.find(i.intern("*goal-env*").as_symbol()) != goos_vars.end());
|
||||
|
||||
EXPECT_TRUE(goos_vars.find(i.intern("*goal-env*").as_symbol())->second ==
|
||||
goal_vars.find(i.intern("*goal-env*").as_symbol())->second);
|
||||
EXPECT_TRUE(goos_vars.find(i.intern("*global-env*").as_symbol())->second ==
|
||||
goal_vars.find(i.intern("*global-env*").as_symbol())->second);
|
||||
EXPECT_TRUE(goos_vars.find(i.intern("*global-env*").as_symbol())->second !=
|
||||
goos_vars.find(i.intern("*goal-env*").as_symbol())->second);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Confirm that the GOOS Library is loaded automatically on interpreter start.
|
||||
*/
|
||||
@@ -1047,10 +1022,10 @@ TEST(GoosObject, Char) {
|
||||
*/
|
||||
TEST(GoosObject, Symbol) {
|
||||
SymbolTable st, st2;
|
||||
Object obj = SymbolObject::make_new(st, "test1");
|
||||
Object obj2 = SymbolObject::make_new(st, "test2");
|
||||
Object obj3 = SymbolObject::make_new(st, "test1");
|
||||
Object obj4 = SymbolObject::make_new(st2, "test1");
|
||||
Object obj = Object::make_symbol(&st, "test1");
|
||||
Object obj2 = Object::make_symbol(&st, "test2");
|
||||
Object obj3 = Object::make_symbol(&st, "test1");
|
||||
Object obj4 = Object::make_symbol(&st2, "test1");
|
||||
|
||||
// check type
|
||||
EXPECT_TRUE(obj.is_symbol());
|
||||
@@ -1173,9 +1148,9 @@ TEST(GoosSpecialForms, Define) {
|
||||
Object goal_env;
|
||||
EXPECT_TRUE(i.get_global_variable_by_name("*goal-env*", &goal_env));
|
||||
|
||||
auto x_in_goal_env = goal_env.as_env()->vars.find(i.intern("x").as_symbol());
|
||||
EXPECT_TRUE(x_in_goal_env != goal_env.as_env()->vars.end());
|
||||
EXPECT_EQ(x_in_goal_env->second.print(), "20");
|
||||
auto x_in_goal_env = goal_env.as_env()->vars.lookup(i.intern("x").as_symbol());
|
||||
EXPECT_TRUE(x_in_goal_env);
|
||||
EXPECT_EQ(x_in_goal_env->print(), "20");
|
||||
|
||||
// test automatic environment of define
|
||||
e(i, "(begin (desfun test-define () (define x 500)) (test-define))");
|
||||
|
||||
Reference in New Issue
Block a user