Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

LUAFDN-268 optimize createSignal memory usage #304

Merged

Conversation

yjia2
Copy link
Contributor

@yjia2 yjia2 commented May 10, 2021

Closes LUAFDN-268.

DUAR has an "not enough memory" issue in production at createSignal. QA was able to reproduce it occasionally during logout. The memory consumption can spike as high as 3.4GB during logout. Inspected with on-screen profiler, it is the StyleConsumer unmount that are operating during the memory spike and createSignal.disconnect() takes the vast majority of the time. Consequently, we believe the createSignal is the root cause of the memory spikes during logout.

The current createSignal's copy-on-add algorithm is primarily for allowing adding new listeners during signal firing. But it is not memory efficient when handling a massive amount of listeners. Hence, the team decides to use an additional static table to hold the new listeners during firing instead of copying everything to an entirely new table.

Checklist before submitting:

  • [c] Added entry to CHANGELOG.md
  • [c] Added/updated relevant tests
  • [-] Added/updated documentation

@coveralls
Copy link

coveralls commented May 10, 2021

Coverage Status

Coverage remained the same at 94.188% when pulling 725b4f5 on yjia2:feature/LUAFDN-268-optimize-createSignal-memory-usage into 6ebe383 on Roblox:master.

@github-actions
Copy link

github-actions bot commented May 10, 2021

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@yjia2
Copy link
Contributor Author

yjia2 commented May 11, 2021

I have read the CLA Document and I hereby sign the CLA

@yjia2 yjia2 marked this pull request as draft May 11, 2021 00:39
@yjia2 yjia2 marked this pull request as ready for review May 11, 2021 00:40
Copy link
Contributor

@ZoteTheMighty ZoteTheMighty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks reasonable to me. Since this is a critical part of the codebase, I'd like some more eyes on it! @matthargett and @oltrep, what do you think?

CHANGELOG.md Outdated
@@ -3,6 +3,7 @@
## Unreleased Changes
* Added color schemes for documentation based on user preference ([#290](https://github.com/Roblox/roact/pull/290)).
* Fixed stack trace level when throwing an error in `createReconciler` ([#297](https://github.com/Roblox/roact/pull/297)).
* Optimized the memory usage of 'createSignal' implementation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a link to the PR like the other items in the list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

expect(spyA.callCount).to.equal(1)
end)

it("should have one connection instance when add the same listener multiple times", function()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have it warn the user when adding the same one multiple times? when this happens, it's probably the symptom of a deeper bug, right?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth, we try to be cautious about warnings when Roact powers things like in-game menu and studio plugins. React doesn't actually expose its signal implementation, so warning about this would signal an internal bug. If this cropped up in shipped code, we'd end up confusingly printing warnings to developers in studio about things that have nothing to do with them!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a warning message.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm a bit worried about the warning too, I am not sure if that can bubble up to the consumers of Roact. I've checked out createContext and Binding and it seems ok to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove it for now. We can loop back on the warning message in a separate PR if necessary

Copy link
Contributor

@matthargett matthargett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, but would like to see the warning message if it's possible. We can do that in a separate PR.

expect(spyA.callCount).to.equal(1)
end)

it("should have one connection instance when add the same listener multiple times", function()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm a bit worried about the warning too, I am not sure if that can bubble up to the consumers of Roact. I've checked out createContext and Binding and it seems ok to me

@oltrep oltrep merged commit 8312f84 into Roblox:master May 13, 2021
@yjia2 yjia2 deleted the feature/LUAFDN-268-optimize-createSignal-memory-usage branch May 13, 2021 23:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants