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

perf: query fewer historical messages on reconnects #5001

Merged

Conversation

iProdigy
Copy link
Contributor

@iProdigy iProdigy commented Dec 4, 2023

Implements smaller ?limit on recent message query upon reconnects, as suggested in #4989

Note: system_clock is used instead of a strictly monotonic clock in anticipation of the since query parameter robotty/recent-messages2#286

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/providers/recentmessages/Api.cpp Outdated Show resolved Hide resolved
src/providers/recentmessages/Api.cpp Outdated Show resolved Hide resolved
src/providers/twitch/TwitchChannel.cpp Outdated Show resolved Hide resolved
@RAnders00
Copy link
Collaborator

The service at https://recent-messages.robotty.de now has a ?before and ?after parameter. Updated documentation can be found here.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/providers/recentmessages/Api.cpp Outdated Show resolved Hide resolved
src/providers/recentmessages/Api.cpp Outdated Show resolved Hide resolved
@iProdigy iProdigy marked this pull request as ready for review December 5, 2023 19:01
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/providers/recentmessages/Api.cpp Outdated Show resolved Hide resolved
src/providers/recentmessages/Api.cpp Outdated Show resolved Hide resolved
src/providers/recentmessages/Api.cpp Outdated Show resolved Hide resolved
@iProdigy iProdigy requested a review from RAnders00 December 5, 2023 21:39
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/providers/recentmessages/Api.cpp Show resolved Hide resolved
src/providers/twitch/TwitchChannel.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@RAnders00 RAnders00 left a comment

Choose a reason for hiding this comment

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

I hope it's not too many changes, I was just trying to be thorough in all the places that I thought would require changes

src/providers/twitch/TwitchChannel.hpp Outdated Show resolved Hide resolved
src/providers/twitch/TwitchChannel.hpp Outdated Show resolved Hide resolved
src/providers/twitch/TwitchChannel.cpp Outdated Show resolved Hide resolved
Comment on lines 1203 to 1205
const auto duration = std::ceil((now - this->disconnectedAt_) / 1000.0);
limit = std::min(static_cast<int>(duration) * 10,
getSettings()->twitchMessageHistoryLimit.getValue());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const auto duration = std::ceil((now - this->disconnectedAt_) / 1000.0);
limit = std::min(static_cast<int>(duration) * 10,
getSettings()->twitchMessageHistoryLimit.getValue());
const auto disconnectDuration = now - this->disconnectedAt_;
const auto disconnectDurationSeconds = std::chrono::duration_cast<std::chrono::seconds>(disconnectDuration).count();
// At least 10 messages, even on very short reconnects that are < 1 full second
limit = std::min(std::max(disconnectDurationSeconds, 1) * 10, limit);

Copy link
Contributor Author

@iProdigy iProdigy Dec 6, 2023

Choose a reason for hiding this comment

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

i think we actually always want to round up to the nearest int (i.e., treat 999ms as 1s, treat 1100ms as 2s - in the 1100ms case, 10 messages could occur at t=0 and 10 at t=1100)

src/providers/twitch/TwitchChannel.cpp Outdated Show resolved Hide resolved
src/providers/recentmessages/Impl.cpp Outdated Show resolved Hide resolved
src/providers/recentmessages/Impl.hpp Outdated Show resolved Hide resolved
src/providers/twitch/TwitchChannel.cpp Outdated Show resolved Hide resolved
src/providers/twitch/TwitchChannel.cpp Outdated Show resolved Hide resolved
src/providers/twitch/TwitchChannel.cpp Show resolved Hide resolved
@iProdigy iProdigy marked this pull request as draft December 6, 2023 22:02
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/providers/recentmessages/Api.cpp Show resolved Hide resolved
src/providers/recentmessages/Api.cpp Show resolved Hide resolved
src/providers/recentmessages/Api.cpp Show resolved Hide resolved
src/providers/recentmessages/Api.hpp Outdated Show resolved Hide resolved
src/providers/recentmessages/Api.hpp Outdated Show resolved Hide resolved
src/providers/recentmessages/Api.hpp Outdated Show resolved Hide resolved
src/providers/recentmessages/Api.hpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/providers/twitch/TwitchChannel.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/providers/recentmessages/Api.hpp Outdated Show resolved Hide resolved
src/providers/recentmessages/Api.hpp Outdated Show resolved Hide resolved
src/providers/recentmessages/Api.hpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/providers/recentmessages/Api.cpp Show resolved Hide resolved
src/providers/recentmessages/Api.cpp Show resolved Hide resolved
src/providers/recentmessages/Api.cpp Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/providers/recentmessages/Api.cpp Show resolved Hide resolved
src/providers/recentmessages/Api.cpp Show resolved Hide resolved
@iProdigy iProdigy marked this pull request as ready for review December 7, 2023 02:40
@pajlada pajlada self-requested a review December 8, 2023 23:24
Copy link
Member

@pajlada pajlada left a comment

Choose a reason for hiding this comment

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

Looks good to me - can you take a look at the changes I've made to see if they make sense @iProdigy?
After that, I'll go ahead and merge this in.

@iProdigy
Copy link
Contributor Author

iProdigy commented Dec 9, 2023

Changes look good to me! thank you @pajlada and @RAnders00

src/providers/twitch/TwitchChannel.hpp Outdated Show resolved Hide resolved
@pajlada
Copy link
Member

pajlada commented Dec 9, 2023

I'm going to merge this in, but one thing I thought about is the use case for when someone puts their computer to sleep with Chatterino running. Will Chatterino only request 10-20 messages upon the computer waking up in this case?

@pajlada pajlada merged commit 13dc306 into Chatterino:master Dec 9, 2023
18 of 20 checks passed
@RAnders00
Copy link
Collaborator

RAnders00 commented Dec 9, 2023

To be honest we could have skipped the entire ?limit parameter calculation. The before and after parameters do everything for us, and I don't need the ?limit for server performance, filtering by time range without limit or with a high limit is just as efficient, it's all about the number of messages returned.

@pajlada
Copy link
Member

pajlada commented Dec 9, 2023

I made #5009 to track any follow-up changes related to sleep

@iProdigy iProdigy deleted the perf/recent-message-reconnect-load branch December 9, 2023 20:36
@iProdigy
Copy link
Contributor Author

iProdigy commented Dec 9, 2023

To be honest we could have skipped the entire ?limit parameter calculation. The before and after parameters do everything for us, and I don't need the ?limit for server performance, filtering by time range without limit or with a high limit is just as efficient, it's all about the number of messages returned.

even if we omitted limit, the sleep issue would remain since it's likely that markDisconnectedNow occurs after the computer wakes from sleep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants