-
-
Notifications
You must be signed in to change notification settings - Fork 573
Perf: Memoize Render plugin's compile functions (#3915) #4229
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
Open
agentic-sanyam
wants to merge
1
commit into
11ty:main
Choose a base branch
from
agentic-sanyam:fix/issue-3915
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+94
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||
| import test from "ava"; | ||||||
| import fs from "node:fs"; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could pull the functions directly during the import:
Suggested change
|
||||||
|
|
||||||
| import { | ||||||
| default as RenderPlugin, | ||||||
|
|
@@ -7,9 +8,12 @@ import { | |||||
| RenderManager, | ||||||
| } from "../src/Plugins/RenderPlugin.js"; | ||||||
| import Eleventy from "../src/Eleventy.js"; | ||||||
| import TemplateConfig from "../src/TemplateConfig.js"; | ||||||
| import ProjectDirectories from "../src/Util/ProjectDirectories.js"; | ||||||
|
|
||||||
| import { normalizeNewLines } from "./Util/normalizeNewLines.js"; | ||||||
|
|
||||||
|
|
||||||
| async function getTestOutput(input, configCallback = function () {}) { | ||||||
| let elev = new Eleventy(input, "./_site/", { | ||||||
| config: function (eleventyConfig) { | ||||||
|
|
@@ -321,3 +325,55 @@ test("#3368 #3810 config init bug with RenderManager", async (t) => { | |||||
| let results = await elev.toJSON(); | ||||||
| t.is(results[0].content, `<h1>Sign up for our newsletter!</h1>`); | ||||||
| }); | ||||||
|
|
||||||
| async function getSharedConfig() { | ||||||
| let templateConfig = new TemplateConfig(null, false); | ||||||
| templateConfig.setDirectories(new ProjectDirectories()); | ||||||
| await templateConfig.init(); | ||||||
| return templateConfig; | ||||||
| } | ||||||
|
|
||||||
| test("Verify compileFile returns the same function with memoization (shared config)", async (t) => { | ||||||
| const filePath = "./test/stubs-render-plugin/11tyjs-file.njk"; | ||||||
| let templateConfig = await getSharedConfig(); | ||||||
| let options = { templateConfig }; | ||||||
|
|
||||||
| let fn1 = await RenderPluginFile(filePath, options); | ||||||
| let fn2 = await RenderPluginFile(filePath, options); | ||||||
|
|
||||||
| t.is(fn1, fn2); | ||||||
| }); | ||||||
|
|
||||||
| test("Verify compileFile returns different functions for different content (shared config)", async (t) => { | ||||||
| const filePath = "./test/stubs-render-plugin/temp-file.njk"; | ||||||
| fs.writeFileSync(filePath, "content 1"); | ||||||
|
|
||||||
| let templateConfig = await getSharedConfig(); | ||||||
| let options = { templateConfig }; | ||||||
|
|
||||||
| let fn1 = await RenderPluginFile(filePath, options); | ||||||
|
|
||||||
| fs.writeFileSync(filePath, "content 2"); | ||||||
| let fn2 = await RenderPluginFile(filePath, options); | ||||||
|
|
||||||
| t.not(fn1, fn2); | ||||||
|
|
||||||
| if (fs.existsSync(filePath)) { | ||||||
| fs.unlinkSync(filePath); | ||||||
| } | ||||||
| }); | ||||||
|
|
||||||
| test("Verify compile (string) returns the same function with memoization (shared config)", async (t) => { | ||||||
| let templateConfig = await getSharedConfig(); | ||||||
| let options = { templateConfig }; | ||||||
| const content = "Hello {{ name }}"; | ||||||
|
|
||||||
| // Need to mock this.page.templateSyntax if templateLang is not passed | ||||||
| const context = { page: { templateSyntax: "njk" } }; | ||||||
|
|
||||||
| let fn1 = await RenderPluginString.call(context, content, "njk", options); | ||||||
| let fn2 = await RenderPluginString.call(context, content, "njk", options); | ||||||
|
|
||||||
| t.is(fn1, fn2); | ||||||
| }); | ||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't touch the assignments, you can use
constoverlet, generally speaking.