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

feat: alter clipboard thread to move all clipboard loading from main thread #2867

Merged
merged 7 commits into from
Nov 6, 2024

Conversation

dordsor21
Copy link
Member

No description provided.

@dordsor21 dordsor21 requested a review from a team as a code owner August 1, 2024 20:25
@github-actions github-actions bot added the Feature This PR adds a new feature label Aug 1, 2024
@dordsor21
Copy link
Member Author

Currently untested

@dordsor21 dordsor21 force-pushed the feat/alter-clipboard-thread-usage branch 3 times, most recently from 7ab49c8 to e1bd063 Compare September 29, 2024 13:18
@dordsor21 dordsor21 requested review from SirYwell and a team September 29, 2024 13:18
@dordsor21 dordsor21 requested a review from SirYwell October 26, 2024 09:52
@dordsor21 dordsor21 force-pushed the feat/alter-clipboard-thread-usage branch from e1bd063 to fc049d6 Compare October 26, 2024 09:52
@dordsor21 dordsor21 requested a review from a team October 26, 2024 09:52
@dordsor21 dordsor21 requested review from SirYwell and a team October 26, 2024 13:16
Copy link
Member

@SirYwell SirYwell left a comment

Choose a reason for hiding this comment

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

Seems to work

@dordsor21 dordsor21 requested a review from a team October 26, 2024 13:25
Copy link
Member

@PierreSchwang PierreSchwang left a comment

Choose a reason for hiding this comment

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

Seems to work quite nicely

Settings.settings().PATHS.CLIPBOARD + File.separator + getUniqueId() + ".bd"
);
try {
Future<?> fut = Fawe.instance().submitUUIDKeyQueuedTask(getUniqueId(), () -> {
Copy link
Member

Choose a reason for hiding this comment

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

Is it really wanted to enqueue twice? LocalSession#loadCLipboardFromDisk(File) submits a task in the KeyQueuedExecutorService - or is the threading purely for acquiring / synchronizing on the lock?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's done on purpose as we want to ensure that we offload from the main thread in AbstractPlayerActor, but without creating a new thread, or using up a thread in an unrelated thread pool. Since we will end up resubmitting to the queue pool again (which results in immediately running the task) we don't lose anything, but only gain safety in offloading in two places

@@ -423,7 +423,7 @@ default void unregister() {
if (Settings.settings().CLIPBOARD.USE_DISK && Settings.settings().CLIPBOARD.DELETE_ON_LOGOUT) {
session.deleteClipboardOnDisk();
} else if (Settings.settings().CLIPBOARD.USE_DISK) {
Fawe.instance().getClipboardExecutor().submit(getUniqueId(), () -> session.setClipboard(null));
Fawe.instance().submitUUIDKeyQueuedTask(getUniqueId(), () -> session.setClipboard(null));
Copy link
Member

Choose a reason for hiding this comment

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

Kinda the same as my first comment, #setClipboard has basically no work except for synchronizing on the lock - is enqueuing that worth it? Might be required due to the lock holder thread, but that would require getClipboard calls to be enqueued as well, which they aren't.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah so basically "free" synchronization from the main thread without having to wait for any potentially ongoing clipboard loading (players joining and leaving a server instantaneously could otherwise lag the server)

@dordsor21 dordsor21 merged commit eb0f07a into main Nov 6, 2024
9 of 10 checks passed
@dordsor21 dordsor21 deleted the feat/alter-clipboard-thread-usage branch November 6, 2024 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature This PR adds a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants