Comments (6)
(BTW you don't need the eval()
)
Will fix.
from ejs.
Technically this is a breaking change. @mde what do you think?
To fix this, I would need to make EJS output templates like one of these:
-
EJS 1 style:
var buf = [] [...] ;buf.push(data.test) [...] ;return buf.join('')
-
Ternary operator:
var __output = '' [...] ;__output += (data.test) == null ? '' : data.test [...] ;return __output
I'll do some benchmark on these.
from ejs.
ejs v1 comp x 24,390 ops/sec ±1.21% (95 runs sampled)
ejs v2 comp orig (__output) x 7,175 ops/sec ±0.57% (97 runs sampled)
ejs v2 comp buf x 7,111 ops/sec ±0.33% (101 runs sampled)
ejs v2 comp __output x 6,927 ops/sec ±0.39% (103 runs sampled)
ejs v1 x 344,302 ops/sec ±0.55% (100 runs sampled)
ejs v1 !_with x 1,560,845 ops/sec ±0.49% (96 runs sampled)
ejs v2 orig x 143,544 ops/sec ±0.52% (100 runs sampled)
ejs v2 orig !_with x 1,453,962 ops/sec ±0.67% (97 runs sampled)
ejs v2 buf x 192,506 ops/sec ±0.97% (100 runs sampled)
ejs v2 buf !_with x 1,328,785 ops/sec ±1.62% (92 runs sampled)
ejs v2 out x 131,761 ops/sec ±1.15% (94 runs sampled)
ejs v2 out !_with x 1,457,213 ops/sec ±3.15% (88 runs sampled)
<% for (var i = 0; i < data.length; i++) { %>
<% var objects = data[i] %>
<h1><%= data[i].title %></h1>
<% for (var j = 0; j < objects.length; j++) { %>
<% var obj = objects[j] %>
<% if (obj.passed) { %>
<p>Passed: <%= obj.name %></p>
<p>Value: <%= obj.value %></p>
<% } else { %>
<p>Failed: <%= obj.name %></p>
<p>Value: <%= obj.value %></p>
<% } %>
<% } %>
<% } %>
{ data: [
{
title: "Test title",
objects: [
{
name: 'this',
value: 21032,
passed: false
}, {
name: 'test',
value: 0,
passed: true
}
]
}, {
title: "Another data",
objects: [
{
name: 'that',
value: 1012021,
passed: true
}, {
name: 'tset',
value: -2,
passed: false
}
]
}
]}
According to the principle of the least slow I think if we are going to make this change it should use var buf = []
(the original EJS <=1 approach). I am still surprised how much slower EJS 2 is compared to EJS 1. It might be because of EJS 2's length compared to EJS 1 (~550 vs ~370).
from ejs.
Now I read more and more EJS 1 code, I really think it's fairly reusable as EJS v2. The OO stuff and expensive regex matching is really dragging the compilation speed down. EJS v1 depends purely on indexOf
which, believe it or not, is fast.
from ejs.
I seem to remember fixing this for escaped output a long time ago in my original codebase. We can do some rewriting for perf, but it's an easy fix for unescaped output too. I'll push a fix, and we can talk about rewrite and refactor in another GH issue or PR.
from ejs.
Fixed in master in a09d026.
from ejs.
Related Issues (20)
- Option to not overwrite unchanged files when using CLI?
- Functions do not return embedded HTML HOT 2
- Add a precompile step HOT 3
- Update jake dependency to avoid [email protected] snyk vulnerability HOT 1
- Fetching Include from a database? HOT 1
- Client True includes are not getting imports recursively HOT 1
- <%-%> auto converting \n in <br> HOT 1
- I just can’t solve the problem with include, I tried different methods, different syntaxes HOT 1
- global scope of variables HOT 1
- Meterian Scan - Security Issue (concat-map version 0.0.1) HOT 4
- Cannot read properties of null if CSS is linked HOT 2
- Is there a way to use ejs on the front-end? HOT 3
- How can we automate dependencies update in project with placeholders? EJS HOT 1
- Eval issue; "data is not defined" HOT 1
- jake aborted - unable to make/build ejs HOT 2
- uglify is not recognized HOT 1
- async option is not true async 3.1.10
- Include partial inside of another partial HOT 2
- How to deply express app with ejs files on netlify.
- SECURITY.md explained HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ejs.