Skip to content

Commit

Permalink
Remove unused trace logs from injection (inefficient)
Browse files Browse the repository at this point in the history
Relocate timer into inject_class and add log_interval interface for testing/benchmarks
  • Loading branch information
Aurelius7309 committed Aug 6, 2024
1 parent db18c1d commit 21336b8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion core/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
--- MODULE CORE

SMODS = {}
MODDED_VERSION = "1.0.0-ALPHA-0806b-STEAMODDED"
MODDED_VERSION = "1.0.0-ALPHA-0806c-STEAMODDED"
SMODS.id = 'Steamodded'
SMODS.version = MODDED_VERSION:gsub('%-STEAMODDED', '')
SMODS.can_load = true
Expand Down
30 changes: 19 additions & 11 deletions core/game_object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
-- Inject all direct instances `o` of the class by calling `o:inject()`.
-- Also inject anything necessary for the class itself.
function SMODS.GameObject:inject_class()
local inject_time = 0
local start_time = love.timer.getTime()
self:send_to_subclasses('pre_inject_class')
local end_time = love.timer.getTime()
inject_time = end_time - start_time
start_time = end_time
local o = nil
for i, key in ipairs(self.obj_buffer) do
o = self.obj_table[key]
Expand All @@ -160,13 +165,22 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.

-- Setup Localize text
o:process_loc_text()

sendTraceMessage(
('Injected game object %s of type %s')
:format(o.key, o.set), o.set or 'GameObject'
)
if SMODS.config.log_level == 1 and self.log_interval and i%(self.log_interval) == 0 then
end_time = love.timer.getTime()
inject_time = inject_time + end_time - start_time
start_time = end_time
local alert = ('[%s] Injecting %s: %.3f ms'):format(string.rep('0', 4-#tostring(i))..i, self.set, inject_time*1000)
sendTraceMessage(alert, 'TIMER')
boot_print_stage(alert)
end
end
self:send_to_subclasses('post_inject_class')
end_time = love.timer.getTime()
inject_time = inject_time + end_time - start_time
local n = #self.obj_buffer
local alert = ('[%s] Injected %s in %.3f ms'):format(string.rep('0',4-#tostring(n))..n, self.set, inject_time*1000)
sendInfoMessage(alert, 'TIMER')
boot_print_stage(alert)
end

--- Takes control of vanilla objects. Child class must implement get_obj for this to function.
Expand Down Expand Up @@ -218,13 +232,7 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
-- Inject all SMODS Objects that are part of this class or a subclass.
function SMODS.injectObjects(class)
if class.obj_table and class.obj_buffer then
local start_time = love.timer.getTime()
class:inject_class()
local end_time = love.timer.getTime()
local n = #class.obj_buffer
local alert = ('[%s] Injected %s in %.3f ms'):format(string.rep('0',4-#tostring(n))..n, class.set or 'nil', (end_time - start_time)*1000)
sendInfoMessage(alert, 'TIMER')
boot_print_stage(alert)
else
for _, subclass in ipairs(class.subclasses) do SMODS.injectObjects(subclass) end
end
Expand Down

0 comments on commit 21336b8

Please sign in to comment.