Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table allocation free versions of sim commands #5436

Merged
merged 10 commits into from
Sep 19, 2023

Conversation

Garanas
Copy link
Member

@Garanas Garanas commented Sep 15, 2023

This idea started with #5398 where we introduce alternatives to global functions that work for just a single unit, instead of a group of units. The goal is to prevent the allocation of a table with a single array entry in it when we need to apply the function to a single unit.

We can apply the same approach to the simulation. We introduce alternatives that work on a single unit and re-use a single table to efficiently manage memory without the developer being aware of it.

@Garanas Garanas added the area: sim Area that is affected by the Simulation of the Game label Sep 15, 2023
@Garanas Garanas added this to the Development iteration IV milestone Sep 15, 2023
@Garanas
Copy link
Member Author

Garanas commented Sep 15, 2023

A quick-and-dirty benchmark:

local start = GetSystemTimeSecondsOnlyForProfileUse()

for k = 1, 1000 do
    local arr = {self}
end

local diff = (GetSystemTimeSecondsOnlyForProfileUse() - start) * 1000
LOG("New table: " .. tostring(diff)) -- 0.12 ms

local start = GetSystemTimeSecondsOnlyForProfileUse()

local cached = { } 
for k = 1, 1000 do
    cached[1] = self
end

local diff = (GetSystemTimeSecondsOnlyForProfileUse() - start) * 1000
LOG("Reused table: " .. tostring(diff)) -- 0.015 ms

Where self is a unit. See also: 9c54351#diff-74bdc025a96f1e8f643036fed35e40e09ad92bcb5d5ac51af065e1ad7f63d25bR298-R317

@Garanas Garanas changed the title Table allocation free version of IssueMoveOffFactory Table allocation free versions of sim commands Sep 15, 2023
@Garanas
Copy link
Member Author

Garanas commented Sep 15, 2023

@Hdt80bro would you have time to go over the changes, see if I did a hiccup anywhere?

@Garanas Garanas merged commit 171e84d into deploy/fafdevelop Sep 19, 2023
2 checks passed
@Garanas Garanas deleted the performance/issue-move-off-factory branch September 19, 2023 08:15
clyfordv pushed a commit to clyfordv/fa that referenced this pull request Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: sim Area that is affected by the Simulation of the Game
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant