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: rework child rendering to use class #10624

Merged
merged 3 commits into from
Apr 1, 2024
Merged

Conversation

43081j
Copy link
Contributor

@43081j 43081j commented Mar 31, 2024

Quite a lot of garbage collection happens when rendering due to the fact we create anonymous functions when buffering writes (the catch, the destination/write function, etc).

By extracting this logic into a class, we can instead rely on prototype methods which exist once in memory.

Testing

Existing tests should cover this.

Manual testing has happened via the benchmark script to see if any benefit was gained.

Before:

Page Avg (ms) Stdev (ms) Max (ms)
/astro 203.76 38.25 315.99
/md 2.73 1.99 22.16
/mdx 118.25 17.55 220.04

After:

Page Avg (ms) Stdev (ms) Max (ms)
/astro 133.88 25.51 313.56
/md 2.44 1.99 22.00
/mdx 113.79 17.49 206.58

Docs

N/A

Notes to reviewers

This isn't a huge gain so i'm happy to throw it away if you think the numbers are lying, or the code is worse.

the whole renderChild buffering is interesting. thanks to the buffering, we do a lot of garbage collection (which slows execution). however, its probably still faster than doing them in serial.

i do wonder if we can rework to avoid allocating/processing individual buffers per child

Copy link

changeset-bot bot commented Mar 31, 2024

⚠️ No Changeset found

Latest commit: 17d5a6e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Mar 31, 2024
@ematipico ematipico requested review from matthewp and bluwy April 1, 2024 07:17
@bluwy
Copy link
Member

bluwy commented Apr 1, 2024

!bench render

Copy link
Contributor

github-actions bot commented Apr 1, 2024

PR Benchmark

Render

Page Avg (ms) Stdev (ms) Max (ms)
/astro 114.88 24.56 214.83
/md 3.48 2.72 27.51
/mdx 106.33 20.84 199.66

Main Benchmark

Render

Page Avg (ms) Stdev (ms) Max (ms)
/astro 188.29 44.93 284.82
/md 3.48 2.54 25.83
/mdx 105.55 20.79 205.86

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Awesome! The results look great and I think this is worth the change. I tried to improve the rendering part too but didn't get far (#9720)

the whole renderChild buffering is interesting. thanks to the buffering, we do a lot of garbage collection (which slows execution). however, its probably still faster than doing them in serial.

i do wonder if we can rework to avoid allocating/processing individual buffers per child

Do you mean sharing a single buffer between all children? It could be faster but I'm not sure how to queue the second buffer-part until the first is done that way. It's not possible to know the size of a buffer-part ahead of time.

@43081j
Copy link
Contributor Author

43081j commented Apr 1, 2024

Basically we spend a lot of time waiting for garbage collection each time we finish a renderChild

Mostly because we discard the buffer and the promise we were waiting for.

By itself, that isn't much. But when you have thousands of promises in memory, the clean up of them takes a while

I feel like there's a solution that will just click one day in my head 😅 something to do with having one big queue and sorting it at the end before flushing it

43081j added 2 commits April 1, 2024 13:41
Quite a lot of garbage collection happens when rendering due to the fact
we create anonymous functions when buffering writes (the `catch`, the
destination/write function, etc).

By extracting this logic into a class, we can instead rely on prototype
methods which exist once in memory.
Removes the `__` prefix of the private properties to match the
conventions used elsewhere in the repo.
@43081j 43081j force-pushed the buffered-render branch from c0a3f0e to 2eb2f1a Compare April 1, 2024 12:42
@43081j
Copy link
Contributor Author

43081j commented Apr 1, 2024

have updated the private properties and rebased onto main FYI

@bluwy bluwy merged commit 0be26d8 into withastro:main Apr 1, 2024
4 checks passed
@matthewp
Copy link
Contributor

matthewp commented Apr 1, 2024

This looks great, thanks so much @43081j !

@43081j 43081j deleted the buffered-render branch April 1, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants