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

Improve startup performance #408

merged 15 commits into from
Aug 18, 2022

Conversation

creesch
Copy link
Member

@creesch creesch commented Oct 24, 2020

Still a draft but from initial testing it seems to make 1-2 seconds depending on circumstances. Effectively it moves the API calls to get user information forward so they can get started before the DOM is in an interactive state. I also moved most javascript around in the manifest so it should be loaded sooner.

Still a bit of a draft as I put in a lot of console log statements with performance.now() timestamps to get insights in delays and I still need to investigate a few things.

I also did play around with replacing all $body declarations with one TBCore variant with the idea that this might improve performance but that doesn't seem to any impact (maybe in memory usage though, didn't look into that).

I also checked if disabling modules like betterbuttons which still scrape the page in an oldschool way had an effect but that also doesn't seem to be the case.

There is still some more investigating to do to see if we can get out a bit more performance but all things considered from what I can see a lot of the perceived delays is mostly down to the sheer amount of things toolbox does with reddit.

On a final note, on firefox performance seems slightly better compared to chromium based browsers both in visual aspect as in actual numbers.

@eritbh eritbh self-requested a review October 26, 2020 20:39
Copy link
Member

@eritbh eritbh left a comment

Choose a reason for hiding this comment

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

Mostly makes sense to me so far. Left some thoughts.

}
});
}
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.


TBApi.setModHash = modhash => {
TBApi.modhash = modhash;
};
Copy link
Member

Choose a reason for hiding this comment

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

Er... why does this function exist...?

Copy link
Member Author

Choose a reason for hiding this comment

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

To set the modhash :P Has to do with how toolbox is structured, when TBApi is loaded in the modhash isn't known yet. I wanted a clean way to set it once it is known.

Copy link
Member

Choose a reason for hiding this comment

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

Can we not just do TBApi.modhash = stuff from wherever the modhash is retreived?

Copy link
Member Author

Choose a reason for hiding this comment

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

Possibly, but afaik we never directly update class/object values so this did seem like a bit cleaner. There also might have been a technical reason I convinced myself was there, but I can't remember now....

@@ -4,22 +4,22 @@ function initwrapper ({userDetails, newModSubs, cacheDetails}) {
(function (TBCore) {
// We need these before we can do anything.
TBCore.userDetails = userDetails;
TBCore.modhash = userDetails.data.modhash;
TBCore.modhash = TBApi.modhash;
Copy link
Member

Choose a reason for hiding this comment

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

We should really only store this value in one place, why not just replace all TBCore.modhash with TBApi.modhash?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hrm not sure why I did it like this to be honest...

extension/data/tbcore.js Outdated Show resolved Hide resolved
TBui.getBestTextColor.cache = {};
})(window.TBui = window.TBui || {});
if (document.readyState === 'loading') {
document.addEventListener('readystatechange', TBuiInitWrapper, {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be restricted to only run for a certain ready state?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, as long as it isn't loading it is fine.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, so it seems like it's always being called on interactive then. I'd rather call out the state we're targeting explicitly, but that might be too small a nitpick. I see how it works now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Frankly seemed like a wasted check as it really doesn't matter as long as it isn't loading.

extension/data/tbui.js Outdated Show resolved Hide resolved
extension/manifest.json Outdated Show resolved Hide resolved
logger.error('firefox is in incognito mode, toolbox will not work.');
return;
}
console.log('sendInit7', 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.

will probably want to remove these logs eventually

extension/data/tbcore.js Outdated Show resolved Hide resolved
@creesch
Copy link
Member Author

creesch commented Nov 18, 2020

Aside from the obvious stuff that still needs fixing before we merge this I do want to try to get some actual benchmarks with enough datapoints with a few scenarios to see actual benefits. Specifically I came across a article regarding performance from a chrome developer where it was pointed out that changing the DOM while it is still being rendered might actually hurt performance.

With that in mind I still want to experiment with some specific scenarios and try to get tangible date points:

  • Baseline, master as it is now without the above scenarios.
  • Current PR.
  • Current PR with CSS moved to load earlier.
  • Current PR but a change where we don't do the complete init at interactive but ready
  • Same as above but with the CSS moved.

I'd like to try to not only measure reported load times but also visible load times, at what point do we see toolbox being loaded. To that end I'll probably set up a simple test with selenium.

@eritbh
Copy link
Member

eritbh commented Jul 13, 2022

This branch hadn't been updated since before #518 (content script esm) so it was very outdated. I got bored and merged current master back into it; a lot of the original performance changes that were in this branch were tied directly to the old event-based module registration system, so they're not here anymore, but there are a couple changes still relevant:

  • Using a single $body variable rather than recomputing $('body') in some spots
  • Removing TBCore.NO_WIKI_PAGE etc which were just unnecessary re-exported duplicates of the same on TBApi

Diff is much smaller now, could probably be a pretty easy merge.

@eritbh eritbh marked this pull request as ready for review July 13, 2022 19:10
@eritbh eritbh added this to the v6.0 milestone Jul 31, 2022
@creesch creesch merged commit 3b883b6 into master Aug 18, 2022
@creesch creesch deleted the startup-performance branch August 18, 2022 18:19
eritbh added a commit that referenced this pull request Sep 5, 2024
* move init api calls, shuffle timing

* $body = $body doesn't work.

* Move api specific constants to TBApi

* remove weird $body usage

* Make sure tbui gets loaded at the right time.

* Not sure how this got back in there.

* Improve new modmail performance and reliability.

* Only listen to init events once

* Better diff for geo ;)

* Update extension/data/tbcore.js

Co-authored-by: Geo <georgej1088@gmail.com>

* Disable travis unit tests

* Finish moving off TBCore errors and remove them

Co-authored-by: Geo <georgej1088@gmail.com>
Co-authored-by: Erin <erin20913@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants