-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: improve getTemplate() when cache is enabled
Checking for file existence is unnecessary when cache contains entry.
- Loading branch information
Showing
4 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,11 +1,13 @@ | ||
import output from './output' | ||
import tag from './tag' | ||
import demo from './demo' | ||
import layout from './layout' | ||
|
||
async function main () { | ||
await output() | ||
await tag() | ||
await demo() | ||
await layout() | ||
} | ||
|
||
main() |
This file contains 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as Benchmark from 'benchmark' | ||
import Liquid from '../src/liquid' | ||
|
||
const engineOptions = { | ||
root: __dirname, | ||
extname: '.liquid' | ||
} | ||
|
||
const engine = new Liquid(engineOptions) | ||
const cachingEngine = new Liquid({ | ||
...engineOptions, | ||
cache: true | ||
}) | ||
|
||
const template = ` | ||
{% layout "./templates/layout.liquid" %} | ||
{% block body %}a small body{% endblock %} | ||
` | ||
|
||
export default function () { | ||
console.log('--- layout ---') | ||
return new Promise(resolve => { | ||
new Benchmark.Suite('layout') | ||
.add('cache=false', { | ||
defer: true, | ||
fn: (d: any) => engine.parseAndRender(template, {}).then(x => d.resolve(x)) | ||
}) | ||
.add('cache=true', { | ||
defer: true, | ||
fn: (d: any) => cachingEngine.parseAndRender(template, {}).then(x => d.resolve(x)) | ||
}) | ||
.on('cycle', (event: any) => console.log(String(event.target))) | ||
.on('complete', resolve) | ||
.run({ 'async': true }) | ||
}) | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This is a barely empty layout with a body: | ||
{% block body %}{% endblock %} |
This file contains 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