squirrellyjs / squirrelly

Semi-embedded JS template engine that supports helpers, filters, partials, and template inheritance. 4KB minzipped, written in TypeScript ⛺
https://squirrelly.js.org
MIT License
635 stars 83 forks source link

Improve Performance #56

Closed nebrelbug closed 4 years ago

nebrelbug commented 6 years ago

If you can improve performance in any way (without sacrificing functionality) or have any ideas, comment here!

kausha15 commented 6 years ago

Hello @nebrelbug , Can I take up this task ?

bvishal8510 commented 6 years ago

you can refer to https://developers.google.com/speed/pagespeed/insights/ for suggestions to improve sight

nebrelbug commented 6 years ago

@kausha15 yes, that would be great! There's no limit to contributors for this issue, so if you have any ideas you can comment or make a pull request.

nebrelbug commented 6 years ago

@bvishal8510 Pageseed Insights is great, but this issue is about improving the time it takes for the Compile() function to execute

nebrelbug commented 6 years ago

@kausha15 do you have any ideas?

ichiriac commented 5 years ago

Not tested but common parsing problem with regex is that they take way more time than an LR/LL(1) generated parser (some multiple performance improvements) and same room of improvement for hand written lexer/parser (so in principle you can almost divide by 2 or more the parsing costs depending on is your regexes are already optimized) - but this will introduce more code and increase the size of your library ...

nebrelbug commented 5 years ago

@ichiriac thanks for the comment! I've thought of using a parser, but here are some of my concerns:

I think it's still a valid suggestion though. Do you have any favorite JS parsers? Thank you!

ichiriac commented 5 years ago

Hi @nebrelbug,

A good starting point would be pegjs - https://pegjs.org/, but it comes with drawbacks, generated code is ugly, hard to debug, and the resulting code is long, in principle more rapid than regex but still slow.

Next you can write it by hand, all you need is a lexer to extract tokens, and then a grammar parser to expose the AST.

The simplest way to find out if you can improve the performance, and how much it's to try a POC and bench it ...

I'll try an implementation here : https://github.com/ichiriac/squirrelly but I need to change more than just the compile.js file ...

nebrelbug commented 5 years ago

Thanks @ichiriac, that would be great if you could test that!

I've been toying with the idea (since my RegExp is so messy) but I'm not sure that it will end up being faster, since with RegExp I don't have to generate an AST or tokens.

On the other hand, maybe a parser will be much faster. I'm excited to find out!

nebrelbug commented 4 years ago

Hi @ichiriac! I know it's been a while, but I recently published the first betas of Squirrelly v8, which implement many of your suggestions. Is it alright if I add you to the README as a contributor?

ichiriac commented 4 years ago

Hi @nebrelbug, it would be kind 😄, I wished to do more but didn't had time. Glad to see you released the v8, sounds like node's engine 😁

nebrelbug commented 4 years ago

Sweet! @all-contributors please add @ichiriac for code and ideas!

allcontributors[bot] commented 4 years ago

@nebrelbug

I've put up a pull request to add @ichiriac! :tada: