Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
decent perf improvements
  • Loading branch information
diakopter committed Nov 11, 2011
1 parent d1240fb commit 80d077d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 51 deletions.
8 changes: 8 additions & 0 deletions lua/compiler/IndexersReplacements.txt
Expand Up @@ -8,6 +8,8 @@
%.SpecialInvoke [8] # on SharedTable
%.CachedInvoke [9] # on SharedTable
%.TypeCheckCache [10] # on SharedTable
%.CachedFindMethod [11] # on SharedTable
%.TypeCacheID [12] # on SharedTable
%.new%( [1]( # all classes with constructors named new
%.CurrentContext [0] # dual purpose (ThreadContext and RakudoCodeRef instance)
%.OuterForNextInvocation [18] # on RakudoCodeRef
Expand All @@ -21,8 +23,14 @@ Ops%.unbox_num%( Ops[5](
Ops%.unbox_str%( Ops[6](
Ops%.type_object_for%( Ops[43](
Ops%.instance_of%( Ops[44](
DefinednessConstraint%.None 0
DefinednessConstraint%.DefinedOnly 1
DefinednessConstraint%.UndefinedOnly 2
%.STable [1] # on every RakudoObject impl (inner classes of the repr classes)
%.Value [2] # some RakudoObject impl
%.Undefined [3] # some RakudoObject impl
%.Positionals [2] # on P6capture
%.Nameds [3] # on P6capture
%.type_object_for%( [2]( # all REPR impl
%.instance_of%( [3]( # all REPR impl
%.defined%( [4]( # all REPR impl
Expand Down
11 changes: 7 additions & 4 deletions lua/compiler/profiler.lua
Expand Up @@ -74,6 +74,7 @@ function getline (filename, lineno)
end
local SortedResults = {}
local index = 1
local total = 0
for marker, count in pairs(Results) do
local splitted = strsplit(":", marker)
local filename = splitted[1]
Expand All @@ -86,13 +87,15 @@ for marker, count in pairs(Results) do
SortedResults[index] = { marker, count, line }
index = index + 1
end
total = total + count
end

table.sort(SortedResults, function (l, r)
return l[2] > r[2]
end)

local running = 0
for _,v in ipairs(SortedResults) do
print(v[1], v[2], "\n", v[3], "\n")
--print(v[1], v[2], "\n")
end
running = running + v[2]
print(v[1], v[2], running, "\n", v[3])
end
print("total: " .. total)
6 changes: 1 addition & 5 deletions lua/runtime/Metamodel/Representations/P6capture.lua
Expand Up @@ -7,11 +7,7 @@ function makeP6capture ()
local Instance = { ["class"] = "P6capture"};
local mt = { __index = Instance };
function Instance.new (STable)
--return { ["STable"] = STable };
local this = {};
this.STable = STable;
return this;
--return setmetatable(this, mt);
return { STable, nil, nil };
end
Instance[1] = Instance.new;
return Instance;
Expand Down
11 changes: 3 additions & 8 deletions lua/runtime/Metamodel/Representations/P6int.lua
Expand Up @@ -8,12 +8,7 @@ function makeP6int ()
local Instance = { ["class"] = "P6int" };
local mt = { __index = Instance };
function Instance.new (STable)
local this = {};
this.STable = STable;
this.Undefined = false;
this.Value = 0;
return this;
--return setmetatable(this, mt);
return { STable, 0, false };
end
Instance[1] = Instance.new;
return Instance;
Expand All @@ -34,11 +29,11 @@ function makeP6int ()
end
P6int[2] = P6int.type_object_for;
function P6int:instance_of (TC, WHAT)
return Instance.new(WHAT.STable);
return { WHAT.STable, nil };
end
P6int[3] = P6int.instance_of;
function P6int:defined (TC, O)
return not O.Undefined;
return O.Value ~= nil;
end
P6int[4] = P6int.defined;
function P6int:hint_for (TC, ClassHandle, Name)
Expand Down
9 changes: 2 additions & 7 deletions lua/runtime/Metamodel/Representations/P6str.lua
Expand Up @@ -7,10 +7,7 @@ function makeP6str ()
local Instance = { ["class"] = "P6str" };
local mt = { __index = Instance };
function Instance.new (STable)
local this = {};
this.STable = STable;
return this;
--return setmetatable(this, mt);
return { STable, nil };
end
Instance[1] = Instance.new;
return Instance;
Expand All @@ -31,9 +28,7 @@ function makeP6str ()
end
P6str[2] = P6str.type_object_for;
function P6str:instance_of (TC, WHAT)
local instance = Instance.new(WHAT.STable);
instance.Value = "";
return instance;
return { WHAT.STable, nil };
end
P6str[3] = P6str.instance_of;
function P6str:defined (TC, O)
Expand Down
42 changes: 23 additions & 19 deletions lua/runtime/Metamodel/SharedTable.lua
@@ -1,16 +1,9 @@

function makeSharedTable ()
local SharedTable = {};
local mt = { __index = SharedTable };
--local mt = { __index = SharedTable };
local TypeCacheIDSource = 4;
function SharedTable.new ()
local sharedTable = {};
TypeCacheIDSource = TypeCacheIDSource + 4;
sharedTable.TypeCacheID = TypeCacheIDSource;
return setmetatable(sharedTable, mt);
end
SharedTable[1] = SharedTable.new;
function SharedTable:FindMethod (TC, Obj, Name, Hint)
local FindMethod = function (self, TC, Obj, Name, Hint)
local CachedMethod;

-- Does this s-table have a special overridden finder?
Expand Down Expand Up @@ -45,20 +38,25 @@ function makeSharedTable ()
return STable.Invoke(STable, TC, Meth, Cap);
end
end
SharedTable[2] = SharedTable.FindMethod;
function SharedTable:Invoke (TC, Obj, Cap)
if (self.SpecialInvoke ~= nil) then
return self.SpecialInvoke(TC, Obj, Cap);
--SharedTable.FindMethod = FindMethod
--SharedTable[2] = FindMethod;
local Invoke = function (self, TC, Obj, Cap)
local specialInvoke = self.SpecialInvoke;
if (specialInvoke ~= nil) then
return specialInvoke(TC, Obj, Cap);
end
local STable = Obj.STable;
if (STable.CachedInvoke == nil) then
STable.CachedInvoke = STable.FindMethod(STable, TC, Obj, "postcircumfix:<( )>", Hints.NO_HINT);
local CachedInvoke = STable.CachedInvoke;
if (CachedInvoke == nil) then
CachedInvoke = STable.FindMethod(STable, TC, Obj, "postcircumfix:<( )>", Hints.NO_HINT);
STable.CachedInvoke = CachedInvoke;
end
STable = STable.CachedInvoke.STable;
STable = CachedInvoke.STable;
return STable.Invoke(STable, TC, Obj, Cap);
end
SharedTable[3] = SharedTable.Invoke;
function SharedTable:TypeCheck (TC, Obj, Checkee)
--SharedTable.Invoke = Invoke;
--SharedTable[3] = Invoke;
local TypeCheck = function (self, TC, Obj, Checkee)
if (self.TypeCheckCache ~= nil) then
for i = 1, self.TypeCheckCache.Count do
if (self.TypeCheckCache[i] == Checkee) then
Expand All @@ -74,7 +72,13 @@ function makeSharedTable ()
return STable.Invoke(STable, TC, Checker, Cap);
end
end
SharedTable[4] = SharedTable.TypeCheck;
--SharedTable.TypeCheck = TypeCheck;
--SharedTable[4] = TypeCheck;
function SharedTable.new ()
TypeCacheIDSource = TypeCacheIDSource + 4;
return { nil, FindMethod, Invoke, TypeCheck, nil, nil, nil, nil, nil, nil, nil, TypeCacheIDSource };
end
SharedTable[1] = SharedTable.new;
return SharedTable;
end
SharedTable = makeSharedTable();
18 changes: 10 additions & 8 deletions lua/runtime/Runtime/MultiDispatch/DispatchCache.lua
Expand Up @@ -22,12 +22,13 @@ function makeDispatchCache ()
this.ArityCaches = List.create(MAX_ARITY + 1);
return setmetatable(this, mt);
end
local PositionalsToTypeCacheIDs;
DispatchCache[1] = DispatchCache.new;
function DispatchCache:Lookup (Positionals)
if (Positionals.Count <= MAX_ARITY) then
local Cache = self.ArityCaches[Positionals.Count];
if (Cache ~= nil and Cache.NumEntries ~= 0) then
local Seeking = DispatchCache.PositionalsToTypeCacheIDs(Positionals);
local Seeking = PositionalsToTypeCacheIDs(Positionals);

local ci = 1;
for ri = 1, Cache.NumEntries do
Expand All @@ -50,7 +51,8 @@ function makeDispatchCache ()
DispatchCache[2] = DispatchCache.Lookup;
function DispatchCache:Add (Positionals, Result)
if (Positionals.Count <= MAX_ARITY) then
local ToAdd = DispatchCache.PositionalsToTypeCacheIDs(Positionals);
local ToAdd = PositionalsToTypeCacheIDs(Positionals);
local ToAddCount = ToAdd.Count;

local Previous = self.ArityCaches[Positionals.Count];

Expand All @@ -71,7 +73,7 @@ function makeDispatchCache ()
if (New.NumEntries <= MAX_ENTRIES) then
local i = 1;
local j = New.NumEntries * ToAdd.Count;
while (i <= ToAdd.Count) do
while (i <= ToAddCount) do
New.TypeIDs[j] = ToAdd[i];
i = i + 1;
j = j + 1;
Expand All @@ -81,8 +83,8 @@ function makeDispatchCache ()
else
local Evictee = math.random(MAX_ENTRIES + 1);
local i = 1;
local j = Evictee * ToAdd.Count;
while (i <= ToAdd.Count) do
local j = Evictee * ToAddCount;
while (i <= ToAddCount) do
New.TypeIDs[j] = ToAdd[i];
i = i + 1;
j = j + 1;
Expand All @@ -91,12 +93,12 @@ function makeDispatchCache ()
end
end

if (self.ArityCaches[ToAdd.Count] == Previous) then
self.ArityCaches[ToAdd.Count] = New;
if (self.ArityCaches[ToAddCount] == Previous) then
self.ArityCaches[ToAddCount] = New;
end
end
end
function DispatchCache.PositionalsToTypeCacheIDs (Positionals)
PositionalsToTypeCacheIDs = function (Positionals)
local Result = List.create(Positionals.Count);
for i = 1, Positionals.Count do
local STable = Positionals[i].STable;
Expand Down

0 comments on commit 80d077d

Please sign in to comment.