Pierre-Olivier Bédard and Shaina Raskas
a77c37db0a
Docs: YARD tags for some resources
2022-03-16 10:57:56 -04:00
Watson
95e9fa5010
Use String#=~ and Regexp.last_match instead to retrieve the markup content
...
If the first value is only used obtained with String#scan,
it will increase the performance if replace with `String#=~` and `Regexp.last_match`.
### Environment
- MacBook Air (M1, 2020)
- macOS 12.0 beta 7
- Apple M1
- Ruby 3.0.2
### Test code
```ruby
require 'benchmark/ips'
WhitespaceControl = '-'
VariableStart = /\{\{/
VariableEnd = /\}\}/
ContentOfVariable = /\A#{VariableStart}#{WhitespaceControl}?(.*?)#{WhitespaceControl}?#{VariableEnd}\z/om
token = "{{item.product.featured_image | product_img_url: 'thumb' }}"
Benchmark.ips do |x|
x.report("String#scan") { token.scan(ContentOfVariable) {|content| break } }
x.report("String#match") { m = token.match(ContentOfVariable); m[1] }
x.report("String#=~") { token =~ ContentOfVariable; Regexp.last_match(1) }
x.compare!
end
```
### Result
```
Warming up --------------------------------------
String#scan 135.724k i/100ms
String#match 117.397k i/100ms
String#=~ 151.637k i/100ms
Calculating -------------------------------------
String#scan 1.351M (± 0.8%) i/s - 6.786M in 5.021955s
String#match 1.169M (± 1.3%) i/s - 5.870M in 5.020429s
String#=~ 1.520M (± 0.9%) i/s - 7.733M in 5.087427s
Comparison:
String#=~: 1520250.9 i/s
String#scan: 1351399.0 i/s - 1.12x (± 0.00) slower
String#match: 1169384.1 i/s - 1.30x (± 0.00) slower
```
2021-09-26 04:12:53 +09:00
Dylan Thacker-Smith and GitHub
260c863e23
Build the tokenizer through the parse context for liquid-c ( #1386 )
2021-01-07 14:51:41 -05:00
Peter Zhu
5c082472a1
Address comments
2020-10-26 16:16:30 -04:00
Peter Zhu
0bedc71854
Address comments
2020-10-26 15:11:00 -04:00
Peter Zhu
fe66edb825
Freeze block body after parsing completes
2020-10-26 11:06:55 -04:00
Dylan Thacker-Smith
33760f083a
Extract rescue code from BlockBody#render_node for re-use in liquid-c
2020-09-25 11:24:39 -04:00
Dylan Thacker-Smith and GitHub
ca4b9b43af
Port liquid-c bug compatible whitespace trimming ( #1291 )
2020-09-16 16:07:36 -04:00
Dylan Thacker-Smith and GitHub
77084930e9
Bring back silencing of errors in blank nodes for backwards compatibility ( #1292 )
2020-09-15 10:35:18 -04:00
Dylan Thacker-Smith
037b603603
Turn some Liquid::BlockBody methods into class methods for liquid-c
...
So they can be used from a Liquid::C::BlockBody
2020-09-08 14:00:48 -04:00
Dylan Thacker-Smith
e1a2057a1b
Update assign_score during capturing
...
To stop long captures before they grow the heap more then they should.
2020-09-03 11:13:08 -04:00
Dylan Thacker-Smith
ae9dbe0ca7
Fix render length resource limit so it doesn't multiply nested output
2020-09-03 11:13:04 -04:00
Dylan Thacker-Smith and GitHub
3b486425b0
Handle BlockBody#blank? at parse time ( #1287 )
2020-09-03 11:07:13 -04:00
Dylan Thacker-Smith and GitHub
b08bcf00ac
Push interrupts from Continue and Break tags rather than from BlockBody ( #1286 )
2020-09-03 06:55:24 -04:00
Dylan Thacker-Smith and GitHub
0740e8b431
Remove unused quirk allowing liquid tags to close a block it is nested in ( #1284 )
2020-09-03 06:51:56 -04:00
Dylan Thacker-Smith and GitHub
2b11efc3ae
Fix performance regression from introduction of Template#disable_tags ( #1274 )
2020-08-18 11:25:51 -04:00
Dylan Thacker-Smith
ef79fa3898
style: Avoid deep nesting for parsing the liquid tag in the block body
2020-01-09 19:13:13 -05:00
Dylan Thacker-Smith
f7ad602bfc
Fix liquid tag nested in outer block
2020-01-09 19:13:13 -05:00
Alessandro Diogo Brückheimer and Mike Angell
e83b1e4159
Add ForceEqualSignAlignment to .rubocop.yml ( #1190 )
...
* Add ForceEqualSignAlignment to .rubocop.yml
* Revert ForceEqualSignAlignment cop
* Update method alignment
* Undo addition of whitespace to improve readability
* Fix missing alignment
2019-10-21 21:18:48 +10:00
Mike Angell and GitHub
1aa7d3d2ba
Change registers to by symbols ( #1178 )
2019-09-27 04:32:24 +10:00
Mike Angell and GitHub
0db9c56f34
Disable rendering of tag based on register ( #1162 )
...
* Disable rendering of tag based on register
* Improvements to disable tag
* Resolve disbale tag tests
* Test disable_tags register
* disabled_tags is now always avaiable
* Allow multiple tags to be disabled at once
* Move disabled check to block_body
* Code improvements
* Remove redundant nil check
* Improve disabled tag error output
* Improve disable tag API
* Code improvements
* Switch disabled? to not mutate output
* Fix array handling shortcut in disable_tags
2019-09-26 00:18:30 +10:00
Mike Angell and GitHub
b667bcb48b
Shopify stye guide fixes ( #1160 )
2019-09-20 02:08:11 +10:00
0d26f05bb8
Enabled frozen string literals ( #1154 )
...
* Enabled frozen string literals
* Update rubocop config
* Prefer string interpolation in simple cases
Co-Authored-By: Dylan Thacker-Smith <[email protected] >
2019-09-18 13:19:45 +10:00
Mike Angell
799da202df
Apply simple rubocop fixes
2019-08-31 21:58:33 +10:00
Tobias Lütke and GitHub
6eab595fae
Merge pull request #1086 from Shopify/liquid-tag
...
Add {% liquid %} and {% echo %} tags
2019-08-27 15:10:20 -04:00
Florian Weingarten
9640e77805
render_to_output_buffer
2019-04-23 17:06:29 -04:00
Florian Weingarten
2a1ca3152d
liquid without the garbage
2019-04-22 16:34:31 -04:00
Florian Weingarten
c89ce9c2ed
use bytesize, not length
2019-04-17 18:55:13 +01:00
Justin Li
7dc488a73b
Simplifications from review
2019-04-09 15:19:47 -04:00
Justin Li
e6ed804ca5
Fix line number tracking after a non-empty blank token
2019-04-08 18:43:09 -04:00
Justin Li
8d1cd41453
Add {% liquid %}, {% echo %}, and {% local %} tags
2019-04-01 20:08:38 -04:00
Justin Li
39fecd06db
Fix interrupts through includes
2019-03-12 12:18:22 -04:00
Christopher Aue
c086017bc9
refactored and optimized rendering
...
Measures:
1) A while loop is faster than iterating with #each.
2) Check string, variable and block tokens first. They are far more
frequent than interrupt tokens. In their case, checking for an
interrupt can be avoided.
3) String tokens just map to themselves and don't need the special
treatment of BlockBody#render_node (except the resource limit
check).
Benchmark
=========
$ bundle exec rake benchmark:run
Before
------
Run 1)
parse: 41.630 (± 0.0%) i/s - 420.000 in 10.089309s
render: 75.962 (± 3.9%) i/s - 763.000 in 10.066823s
parse & render: 25.497 (± 0.0%) i/s - 256.000 in 10.040862s
Run 2)
parse: 42.130 (± 0.0%) i/s - 424.000 in 10.064738s
render: 77.003 (± 1.3%) i/s - 777.000 in 10.093524s
parse & render: 25.739 (± 0.0%) i/s - 258.000 in 10.024581s
Run 3)
parse: 41.976 (± 2.4%) i/s - 420.000 in 10.021406s
render: 76.184 (± 1.3%) i/s - 763.000 in 10.018104s
parse & render: 25.641 (± 0.0%) i/s - 258.000 in 10.062549s
After
-----
Run 1)
parse: 42.283 (± 0.0%) i/s - 424.000 in 10.028306s
render: 83.158 (± 2.4%) i/s - 832.000 in 10.009201s
parse & render: 26.417 (± 0.0%) i/s - 266.000 in 10.069718s
Run 2)
parse: 41.159 (± 4.9%) i/s - 412.000 in 10.031297s
render: 81.591 (± 3.7%) i/s - 816.000 in 10.018225s
parse & render: 25.924 (± 3.9%) i/s - 260.000 in 10.035653s
Run 3)
parse: 42.418 (± 2.4%) i/s - 424.000 in 10.003100s
render: 84.183 (± 2.4%) i/s - 847.000 in 10.069781s
parse & render: 26.726 (± 0.0%) i/s - 268.000 in 10.029857s
2018-04-19 12:10:15 +02:00
Ashwin Maroli
e4da4d49d2
assign regex to a constant
2018-03-13 23:36:56 +05:30
Dylan Thacker-Smith and GitHub
6c117fd7dd
refactor: Reduce maximum block nesting in Liquid::BlockBody#parse ( #944 )
2017-10-19 10:12:40 -04:00
Dylan Thacker-Smith
7334073be2
Avoid duck typing to detect whether to call render on a node.
2017-02-10 13:49:26 -05:00
Dylan Thacker-Smith
5dcefd7d77
Avoid calling line_number on String node when rescuing a render error.
2017-02-07 15:34:10 -05:00
Richard Monette
a549d289d7
introduce unhandled liquid exception
...
check arity
2016-10-28 09:40:44 -04:00
Michael Angell
283f1bad18
Use .last instead of pop push method for updating last node in nodelist
2016-07-08 20:49:30 +10:00
Michael Angell
e1d40c7d89
Add whitespace control character and associated tests
2016-06-28 09:15:45 +10:00
Ivan Kuznetsov
dadd9b4dd2
Add strict_variables/strict_filters render options to check for undefined variables and filters
2016-02-03 10:49:33 +07:00
Dylan Thacker-Smith
c45310170b
Use parse_context or options instead of @options.
2015-07-08 19:21:59 -04:00
Dylan Thacker-Smith
920e1df643
Rescue and re-raise syntax errors in Template#parse to add line numbers.
...
This can be done now that the parse context has the line number
information, so it doesn't need to be added on closer to the original
exception. This has the advantage of not having to rescue and re-raise the
exception multiple times, and simplifies liquid-c which would otherwise
have to rescue the exception in BlockBody#parse.
2015-07-08 19:21:59 -04:00
Dylan Thacker-Smith
cebf75b8d7
Implement line numbers without the Liquid::Token class.
2015-07-08 19:21:59 -04:00
Dylan Thacker-Smith
fad3b8275c
Use node to refer to objects from the nodelist rather than token.
2015-07-04 20:57:35 -04:00
Florian Weingarten
5919626da4
Rename 'has_key?' and 'has_interrupt?'
2015-06-04 13:14:46 -04:00
Gaurav Chande
79d7dd06df
Extract tag fetching into a method (which can be overriden then)
2015-06-04 04:39:54 +00:00
Florian Weingarten
3372ca8136
Rubocop
2015-05-14 14:37:18 +00:00
Justin Li
c2f71ee86b
Reset resource consumption before each render
2014-12-09 17:23:07 -05:00
Justin Li
9f7e601110
Convert render output to strings in BlockBody
2014-12-05 15:17:09 -05:00