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

Improve startup performance #408

Merged
merged 15 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extension/data/modules/achievements.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,6 @@ function achievements () {

window.addEventListener('TBModuleLoaded', () => {
achievements();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/betterbuttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,4 +518,6 @@ function betterbuttons () {

window.addEventListener('TBModuleLoaded', () => {
betterbuttons();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,4 +548,6 @@ function comments () {

window.addEventListener('TBModuleLoaded', () => {
comments();
}, {
once: true,
});
20 changes: 11 additions & 9 deletions extension/data/modules/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ function tbconfig () {
subreddit = $(this).data('subreddit');

TBApi.readFromWiki(subreddit, 'toolbox', true).then(resp => {
if (!resp || resp === TBCore.WIKI_PAGE_UNKNOWN || resp === TBCore.NO_WIKI_PAGE) {
if (!resp || resp === TBApi.WIKI_PAGE_UNKNOWN || resp === TBApi.NO_WIKI_PAGE) {
self.log('Failed: wiki config');

config = TBCore.config;
Expand Down Expand Up @@ -498,13 +498,13 @@ function tbconfig () {
});

TBApi.readFromWiki(subreddit, actualPage, false).then(resp => {
if (resp === TBCore.WIKI_PAGE_UNKNOWN) {
if (resp === TBApi.WIKI_PAGE_UNKNOWN) {
$textArea.val('error getting wiki data.');
configEditor.setValue('error getting wiki data.');
return;
}

if (resp === TBCore.NO_WIKI_PAGE) {
if (resp === TBApi.NO_WIKI_PAGE) {
$textArea.val('');
configEditor.setValue('');
$saveButton.show();
Expand All @@ -531,12 +531,12 @@ function tbconfig () {
$textArea.val('getting wiki data...');

TBApi.readFromWiki(subreddit, actualPage, false).then(resp => {
if (resp === TBCore.WIKI_PAGE_UNKNOWN) {
if (resp === TBApi.WIKI_PAGE_UNKNOWN) {
$textArea.val('error getting wiki data.');
return;
}

if (resp === TBCore.NO_WIKI_PAGE) {
if (resp === TBApi.NO_WIKI_PAGE) {
$textArea.val('');
$saveButton.show();
$saveButton.attr('page', page);
Expand Down Expand Up @@ -903,7 +903,7 @@ function tbconfig () {
// determine if we want to pull a new config, we only do this if the toolbox config wiki has been edited.
if ($body.hasClass('toolbox-wiki-edited')) {
TBApi.readFromWiki(subreddit, 'toolbox', true).then(resp => {
if (!resp || resp === TBCore.WIKI_PAGE_UNKNOWN || resp === TBCore.NO_WIKI_PAGE) {
if (!resp || resp === TBApi.WIKI_PAGE_UNKNOWN || resp === TBApi.NO_WIKI_PAGE) {
self.log('Failed: wiki config');
return;
}
Expand Down Expand Up @@ -1053,7 +1053,7 @@ function tbconfig () {
// determine if we want to pull a new config, we only do this if the toolbox config wiki has been edited.
if ($body.hasClass('toolbox-wiki-edited')) {
TBApi.readFromWiki(subreddit, 'toolbox', true).then(resp => {
if (!resp || resp === TBCore.WIKI_PAGE_UNKNOWN || resp === TBCore.NO_WIKI_PAGE) {
if (!resp || resp === TBApi.WIKI_PAGE_UNKNOWN || resp === TBApi.NO_WIKI_PAGE) {
self.log('Failed: wiki config');
return;
}
Expand Down Expand Up @@ -1247,7 +1247,7 @@ function tbconfig () {
// determine if we want to pull a new config, we only do this if the toolbox config wiki has been edited.
if ($body.hasClass('toolbox-wiki-edited')) {
TBApi.readFromWiki(subreddit, 'toolbox', true).then(resp => {
if (!resp || resp === TBCore.WIKI_PAGE_UNKNOWN || resp === TBCore.NO_WIKI_PAGE) {
if (!resp || resp === TBApi.WIKI_PAGE_UNKNOWN || resp === TBApi.NO_WIKI_PAGE) {
self.log('Failed: wiki config');
return;
}
Expand Down Expand Up @@ -1330,7 +1330,7 @@ function tbconfig () {
// determine if we want to pull a new config, we only do this if the toolbox config wiki has been edited.
if ($body.hasClass('toolbox-wiki-edited')) {
TBApi.readFromWiki(subreddit, 'toolbox', true).then(resp => {
if (!resp || resp === TBCore.WIKI_PAGE_UNKNOWN || resp === TBCore.NO_WIKI_PAGE) {
if (!resp || resp === TBApi.WIKI_PAGE_UNKNOWN || resp === TBApi.NO_WIKI_PAGE) {
self.log('Failed: wiki config');
return;
}
Expand Down Expand Up @@ -1621,4 +1621,6 @@ function tbconfig () {

window.addEventListener('TBModuleLoaded', () => {
tbconfig();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,6 @@ function devtools () {

window.addEventListener('TBModuleLoaded', () => {
devtools();
}, {
once: true,
});
6 changes: 4 additions & 2 deletions extension/data/modules/domaintagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ function domaintagger () {
let {config} = TBCore;

TBApi.readFromWiki(subreddit, 'toolbox', true).then(resp => {
if (resp === TBCore.WIKI_PAGE_UNKNOWN) {
if (resp === TBApi.WIKI_PAGE_UNKNOWN) {
return;
}

if (resp === TBCore.NO_WIKI_PAGE) {
if (resp === TBApi.NO_WIKI_PAGE) {
config.domainTags = [domainTag];
postToWiki(subreddit, config, 'domain tagger: create new toolbox config');
return;
Expand Down Expand Up @@ -314,4 +314,6 @@ function domaintagger () {

window.addEventListener('TBModuleLoaded', () => {
domaintagger();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/flyingsnoo.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,6 @@ function flyingsnoo () {

window.addEventListener('TBModuleLoaded', () => {
flyingsnoo();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ function generalSettings () {

window.addEventListener('TBModuleLoaded', () => {
generalSettings();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/historybutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,4 +826,6 @@ function historybutton () {

window.addEventListener('TBModuleLoaded', () => {
historybutton();
}, {
once: true,
});
10 changes: 6 additions & 4 deletions extension/data/modules/macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ function modmacros () {
callback(checkConfig(TBCore.configCache[sub]), TBCore.configCache[sub].modMacros);
} else {
TBApi.readFromWiki(sub, 'toolbox', true).then(resp => {
if (!resp || resp === TBCore.WIKI_PAGE_UNKNOWN) {
self.log('!resp || resp === TBCore.WIKI_PAGE_UNKNOWN');
if (!resp || resp === TBApi.WIKI_PAGE_UNKNOWN) {
self.log('!resp || resp === TBApi.WIKI_PAGE_UNKNOWN');
callback(false);
}

if (resp === TBCore.NO_WIKI_PAGE) {
self.log('resp === TBCore.NO_WIKI_PAGE');
if (resp === TBApi.NO_WIKI_PAGE) {
self.log('resp === TBApi.NO_WIKI_PAGE');
TBCore.updateCache('noConfig', sub, false);
callback(false);
}
Expand Down Expand Up @@ -554,4 +554,6 @@ function modmacros () {

window.addEventListener('TBModuleLoaded', () => {
modmacros();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/modbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,8 @@ function modbar () {

window.addEventListener('TBModuleLoaded', () => {
modbar();
}, {
once: true,
});
function getDirectingTo () {
let url = window.location.href.replace(/^http:/, 'https:'),
Expand Down
2 changes: 2 additions & 0 deletions extension/data/modules/modbutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,4 +684,6 @@ function modbutton () {

window.addEventListener('TBModuleLoaded', () => {
modbutton();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/modmailpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -1048,4 +1048,6 @@ function modmailpro () {

window.addEventListener('TBModuleLoaded', () => {
modmailpro();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/modmatrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,4 +796,6 @@ ${renderedMarkdown}

window.addEventListener('TBModuleLoaded', () => {
modmatrix();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/newmodmailpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,6 @@ function newmodmailpro () {

window.addEventListener('TBModuleLoaded', () => {
newmodmailpro();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,4 +786,6 @@ function notifiermod () {

window.addEventListener('TBModuleLoaded', () => {
notifiermod();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/nukecomments.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,6 @@ function nukecomments () {

window.addEventListener('TBModuleLoaded', () => {
nukecomments();
}, {
once: true,
});
22 changes: 17 additions & 5 deletions extension/data/modules/oldreddit.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ function oldReddit () {
}

self.init = function () {
profileResults('oldRedditInit', performance.now());
// Looks like we are on old reddit. Activate!
if (TBCore.isOldReddit) {
setTimeout(() => {
Expand All @@ -247,7 +248,7 @@ function oldReddit () {
window.addEventListener('TBNewThings', () => {
thingCrawler();
});
}, 500);
}, 10);
}

if (TBCore.isNewModmail) {
Expand All @@ -267,16 +268,27 @@ function oldReddit () {

window.addEventListener('TBNewPage', event => {
if (event.detail.pageType === 'modmailConversation') {
setTimeout(() => {
newModmailSidebar();
newModmailConversationAuthors();
}, 500);
// We want to show buttons as soone as possible.
// New modmail loading times are less than reliable at times.
// So we simply check multiple times in a row to show things as soon as possible.
const timeoutArray = [50, 500, 1500];
timeoutArray.forEach(timeout => {
setTimeout(() => {
newModmailSidebar();
newModmailConversationAuthors();
}, timeout);
});
}
});
}
profileResults('oldRedditInitDone', performance.now());
Copy link
Member

Choose a reason for hiding this comment

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

This profile is basically useless since all that's being done between here and oldRedditInit is setting a bunch of timeouts.

};
}

window.addEventListener('TBModuleLoaded', () => {
profileResults('oldRedditStart', performance.now());
oldReddit();
profileResults('oldRedditDone', performance.now());
}, {
once: true,
});
6 changes: 4 additions & 2 deletions extension/data/modules/personalnotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ function personalnotes () {
$editArea.css('display', 'block');

TBApi.readFromWiki(notewiki, `notes/${wikiPage}`, false).then(resp => {
if (resp === TBCore.WIKI_PAGE_UNKNOWN) {
if (resp === TBApi.WIKI_PAGE_UNKNOWN) {
$editArea.val('error getting wiki data.');
TB.ui.textFeedback('error getting wiki data.', TB.ui.FEEDBACK_NEGATIVE);
return;
}

if (resp === TBCore.NO_WIKI_PAGE) {
if (resp === TBApi.NO_WIKI_PAGE) {
$editArea.val('Not sure how you did this, but this is not an existing page.');
TB.ui.textFeedback('error getting wiki data.', TB.ui.FEEDBACK_NEGATIVE);
return;
Expand Down Expand Up @@ -295,4 +295,6 @@ function personalnotes () {

window.addEventListener('TBModuleLoaded', () => {
personalnotes();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,4 +923,6 @@ function profilepro () {

window.addEventListener('TBModuleLoaded', () => {
profilepro();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/queue_overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,6 @@ function queueOverlay () {

window.addEventListener('TBModuleLoaded', () => {
queueOverlay();
}, {
once: true,
});
6 changes: 4 additions & 2 deletions extension/data/modules/queuetools.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,12 @@ function queuetools () {
<p><label><input type="checkbox" class="choice" name="links" /> submissions</label></p>
<p><label><input type="checkbox" class="choice" name="self" /> text posts</label></p>
<p><label><input type="checkbox" class="choice" name="flair" /> posts with flair</label></p>

<p class="divider"><input type="text" class="choice tb-input" name="domain" placeholder="domain..." /></p>
<p><input type="text" class="choice tb-input" name="user" placeholder="user..." /></p>
<p><input type="text" class="choice tb-input" name="title" placeholder="title..." /></p>
<p><input type="text" class="choice tb-input" name="subreddit" placeholder="subreddit..." /></p>

<h2 class="divider">Conditional</h2>
<p><input type="text" class="choice tb-input" name="pointsgt" placeholder="points >..." /></p>
<p><input type="text" class="choice tb-input" name="pointslt" placeholder="points <..." /></p>
Expand Down Expand Up @@ -1439,4 +1439,6 @@ Action reason: ${value.data.details}

window.addEventListener('TBModuleLoaded', () => {
queuetools();
}, {
once: true,
});
4 changes: 3 additions & 1 deletion extension/data/modules/removalreasons.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function removalreasons () {

// OK, they are not cached. Try the wiki.
TBApi.readFromWiki(subreddit, 'toolbox', true).then(resp => {
if (!resp || resp === TBCore.WIKI_PAGE_UNKNOWN || resp === TBCore.NO_WIKI_PAGE || !resp.removalReasons) {
if (!resp || resp === TBApi.WIKI_PAGE_UNKNOWN || resp === TBApi.NO_WIKI_PAGE || !resp.removalReasons) {
self.log('failed: wiki config');
callback(false);
return;
Expand Down Expand Up @@ -938,4 +938,6 @@ function removalreasons () {

window.addEventListener('TBModuleLoaded', () => {
removalreasons();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ Info| &nbsp;

window.addEventListener('TBModuleLoaded', () => {
support();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,6 @@ function syntax () {

window.addEventListener('TBModuleLoaded', () => {
syntax();
}, {
once: true,
});
2 changes: 2 additions & 0 deletions extension/data/modules/trouble.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,6 @@ function trouble () {

window.addEventListener('TBModuleLoaded', () => {
trouble(); // run
}, {
once: true,
});
Loading