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: cache layout access check #414

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

mweberxyz
Copy link
Contributor

@mweberxyz mweberxyz commented Feb 27, 2024

Specifying a layout on render causes a synchronous fs.accessSync on every request. Cache the result of these lookups in LRU to avoid duplicate blocking checks.

Benchmarks (master)

fastify-ejs-local-layout.js: 84885.34 req/s
fastify-ejs-global-layout.js: 115680 req/s

Benchmarks (PR)

fastify-ejs-local-layout.js: 114592 req/s
fastify-ejs-global-layout.js: 116917.34 req/s

Checklist

gurgunday
gurgunday previously approved these changes Feb 27, 2024
Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

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

lgtm

@gurgunday
Copy link
Member

Can you replace hashlru with toad-cache (LruMap) in another PR?

We try to use that for all the packages now, unless there is a significant perf regression

Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

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

Actually, just checked the PR again and it looks to me like this function gets called once?

Is that not the case?

@mweberxyz
Copy link
Contributor Author

Actually, just checked the PR again and it looks to me like this function gets called once?

Is that not the case?

It gets called a single time for a globally defined layout.

It gets called on every request (via layoutIsValid) for a reply-defined layout, ie -

reply.view('index-for-layout.ejs', { text: 'text' }, { layout: 'layout.html' })

@mweberxyz mweberxyz marked this pull request as draft February 28, 2024 19:39
@mweberxyz
Copy link
Contributor Author

Marked as draft to let #416 and the subsequent toad-lru PR merge first to avoid conflict.

@mweberxyz mweberxyz mentioned this pull request Feb 28, 2024
2 tasks
@mweberxyz mweberxyz force-pushed the perf/cache-layout-access-check branch from 07e87e0 to e13dbd0 Compare March 1, 2024 16:07
@mweberxyz mweberxyz marked this pull request as ready for review March 1, 2024 16:09
@mweberxyz mweberxyz requested a review from gurgunday March 1, 2024 16:10
Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

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

lgtm

@gurgunday gurgunday merged commit 2fa7ee8 into fastify:master Mar 6, 2024
19 checks passed
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.

None yet

2 participants