Skip to content

Load features faster - #4316

Merged
yakov116 merged 8 commits into
mainfrom
load_css_faster
May 7, 2021
Merged

yakov116 merged 8 commits into
mainfrom
load_css_faster

Conversation

@yakov116

@yakov116 yakov116 commented May 4, 2021

Copy link
Copy Markdown
Member

Closes #4312

From 280ms to 39.458984375 ms

Test URLs

All

Screenshot

None

@yakov116
yakov116 requested a review from fregante May 4, 2021 03:44
Comment thread source/features/index.tsx Outdated
Comment on lines +86 to +89
while (!document.body) {
// eslint-disable-next-line no-await-in-loop
await Promise.race([delay(10), frame()]);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If frame resolves, we definitely have body too.

Suggested change
while (!document.body) {
// eslint-disable-next-line no-await-in-loop
await Promise.race([delay(10), frame()]);
}
const oneFrame = frame();
while (!document.body) {
// eslint-disable-next-line no-await-in-loop
await Promise.race([delay(10), oneFrame]);
}

Maybe there's a "better" way to write it though

Suggested change
while (!document.body) {
// eslint-disable-next-line no-await-in-loop
await Promise.race([delay(10), frame()]);
}
await Promise.race([frame(), pWaitFor(() => document.body)]);

but unless we already have the dependency, I'd rather not

https://www.npmjs.com/package/p-wait-for

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

but unless we already have the dependency

its not

Comment thread source/features/index.tsx Resolved
@yakov116

yakov116 commented May 6, 2021

Copy link
Copy Markdown
Member Author

Title good?

@yakov116
yakov116 merged commit cdebcef into main May 7, 2021
@yakov116
yakov116 deleted the load_css_faster branch May 7, 2021 16:57
yakov116 added a commit that referenced this pull request May 10, 2021
yakov116 added a commit that referenced this pull request May 10, 2021
@fregante

fregante commented May 11, 2021 •

Copy link
Copy Markdown
Member

I have a hunch about what's causing the issue here: Firefox is easily tricked into rendering the content before it's ready, therefore resolving the frame() promise. This means that the race resolves immediately and causes the CPU to spike even if technically it's not blocking the thread.

We had this issue in Refined GitHub before but I don't remember what caused it. I think some extensions are triggering this behavior and wreaking havoc in the loop.

Can you restore this PR and instead use code like:

	await Promise.race([
		// With comments
		elementReady('body', {waitForChildren: false})

		// Maybe written better?
		(async () => {
			while (!document.body) {
				await delay(10);
			}
		})()
	]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Custom CSS is injected too late

2 participants