liquid-c 4.0.1 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/cla.yml +23 -0
  3. data/.github/workflows/liquid.yml +36 -11
  4. data/.gitignore +4 -0
  5. data/.rubocop.yml +14 -0
  6. data/Gemfile +15 -5
  7. data/README.md +32 -8
  8. data/Rakefile +12 -63
  9. data/ext/liquid_c/block.c +493 -60
  10. data/ext/liquid_c/block.h +28 -2
  11. data/ext/liquid_c/c_buffer.c +42 -0
  12. data/ext/liquid_c/c_buffer.h +76 -0
  13. data/ext/liquid_c/context.c +233 -0
  14. data/ext/liquid_c/context.h +70 -0
  15. data/ext/liquid_c/document_body.c +97 -0
  16. data/ext/liquid_c/document_body.h +59 -0
  17. data/ext/liquid_c/expression.c +116 -0
  18. data/ext/liquid_c/expression.h +24 -0
  19. data/ext/liquid_c/extconf.rb +21 -9
  20. data/ext/liquid_c/intutil.h +22 -0
  21. data/ext/liquid_c/lexer.c +39 -3
  22. data/ext/liquid_c/lexer.h +18 -3
  23. data/ext/liquid_c/liquid.c +76 -6
  24. data/ext/liquid_c/liquid.h +24 -1
  25. data/ext/liquid_c/liquid_vm.c +618 -0
  26. data/ext/liquid_c/liquid_vm.h +25 -0
  27. data/ext/liquid_c/parse_context.c +76 -0
  28. data/ext/liquid_c/parse_context.h +13 -0
  29. data/ext/liquid_c/parser.c +153 -65
  30. data/ext/liquid_c/parser.h +4 -2
  31. data/ext/liquid_c/raw.c +136 -0
  32. data/ext/liquid_c/raw.h +6 -0
  33. data/ext/liquid_c/resource_limits.c +279 -0
  34. data/ext/liquid_c/resource_limits.h +23 -0
  35. data/ext/liquid_c/stringutil.h +44 -0
  36. data/ext/liquid_c/tokenizer.c +149 -35
  37. data/ext/liquid_c/tokenizer.h +20 -9
  38. data/ext/liquid_c/usage.c +18 -0
  39. data/ext/liquid_c/usage.h +9 -0
  40. data/ext/liquid_c/variable.c +196 -20
  41. data/ext/liquid_c/variable.h +18 -1
  42. data/ext/liquid_c/variable_lookup.c +44 -0
  43. data/ext/liquid_c/variable_lookup.h +8 -0
  44. data/ext/liquid_c/vm_assembler.c +491 -0
  45. data/ext/liquid_c/vm_assembler.h +240 -0
  46. data/ext/liquid_c/vm_assembler_pool.c +99 -0
  47. data/ext/liquid_c/vm_assembler_pool.h +26 -0
  48. data/lib/liquid/c/compile_ext.rb +44 -0
  49. data/lib/liquid/c/version.rb +3 -1
  50. data/lib/liquid/c.rb +226 -48
  51. data/liquid-c.gemspec +16 -10
  52. data/performance/c_profile.rb +23 -0
  53. data/performance.rb +6 -4
  54. data/rakelib/compile.rake +15 -0
  55. data/rakelib/integration_test.rake +43 -0
  56. data/rakelib/performance.rake +43 -0
  57. data/rakelib/rubocop.rake +6 -0
  58. data/rakelib/unit_test.rake +14 -0
  59. data/test/integration_test.rb +11 -0
  60. data/test/liquid_test_helper.rb +21 -0
  61. data/test/test_helper.rb +21 -2
  62. data/test/unit/block_test.rb +137 -0
  63. data/test/unit/context_test.rb +85 -0
  64. data/test/unit/expression_test.rb +191 -0
  65. data/test/unit/gc_stress_test.rb +28 -0
  66. data/test/unit/raw_test.rb +93 -0
  67. data/test/unit/resource_limits_test.rb +50 -0
  68. data/test/unit/tokenizer_test.rb +90 -20
  69. data/test/unit/variable_test.rb +279 -60
  70. metadata +60 -11
  71. data/test/liquid_test.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e8ca00871b405a80337964e8d16fbd9e2c7eebc1174e04149193ed2b6dec69e
4
- data.tar.gz: 6beb1f9af62e04c208735e733536631b0bb48a734f6f25a79e69e0032a71b6df
3
+ metadata.gz: 8b5a8a5b1b5f7409b378626e889898eeac6996ef2127894d25d2f342183c633c
4
+ data.tar.gz: 165117bbbcf583f3c9c0223c3232de5e5c42b67a8ed90b3d268864e4732c685d
5
5
  SHA512:
6
- metadata.gz: 9f6eb35fdd601a8ecc6d1f00beb3ef4d06ecb51c0de7fe5e9efbe9795d9ddc9828f5b0a4fe65cb719d91b322d3162a61e561c45b03f6cafebdc773a1f6bf2b7e
7
- data.tar.gz: d2c21226bb648cdd9b062997fede49f6b0a2bc8896c216c5e66554b4962cd9524fe0a09b25450f8a1ac76bce2cf7f61ccdec039bc35079ce28cb0770c4a6cfbf
6
+ metadata.gz: a7c7ed2cd71c5470c4b53671611279e71279cba16f0a6fcd5623935b80373ed941f6b3360264399ec7f8ab1efe39728f0bba1a6fecdd3e704675e7464ab660aa
7
+ data.tar.gz: 006af34fd3a151cae0387a0d70f18e5f64f98dba95f1e2bf6ea36fe239db3153f301405c349ff25a852977ad38b8873a6d8b2554753f29f37665ef20f7a30fda
@@ -0,0 +1,23 @@
1
+ # .github/workflows/cla.yml
2
+ name: Contributor License Agreement (CLA)
3
+
4
+ on:
5
+ pull_request_target:
6
+ types: [opened, synchronize]
7
+ issue_comment:
8
+ types: [created]
9
+
10
+ jobs:
11
+ cla:
12
+ runs-on: ubuntu-latest
13
+ if: |
14
+ (github.event.issue.pull_request
15
+ && !github.event.issue.pull_request.merged_at
16
+ && contains(github.event.comment.body, 'signed')
17
+ )
18
+ || (github.event.pull_request && !github.event.pull_request.merged)
19
+ steps:
20
+ - uses: Shopify/shopify-cla-action@v1
21
+ with:
22
+ github-token: ${{ secrets.GITHUB_TOKEN }}
23
+ cla-token: ${{ secrets.CLA_TOKEN }}
@@ -5,19 +5,44 @@ jobs:
5
5
  runs-on: ubuntu-latest
6
6
  strategy:
7
7
  matrix:
8
- entry:
9
- - { ruby: 2.7 }
10
- - { ruby: 3.2 }
11
- name: test (${{ matrix.entry.ruby }})
8
+ include:
9
+ - { ruby: '2.7', allowed-failure: false }
10
+ - { ruby: '3.0', allowed-failure: false }
11
+ - { ruby: '3.1', allowed-failure: false }
12
+ - { ruby: '3.2', allowed-failure: false }
13
+ - { ruby: '3.3', allowed-failure: false }
14
+ - { ruby: ruby-head, allowed-failure: true }
15
+ - { ruby: truffleruby-head, allowed-failure: true }
16
+ name: test (${{ matrix.ruby }})
12
17
  steps:
13
18
  - uses: actions/checkout@v2
14
19
  - uses: ruby/setup-ruby@v1
15
20
  with:
16
- ruby-version: ${{ matrix.entry.ruby }}
17
- - uses: actions/cache@v1
18
- with:
19
- path: vendor/bundle
20
- key: ${{ runner.os }}-gems-${{ hashFiles('Gemfile') }}
21
- restore-keys: ${{ runner.os }}-gems-
22
- - run: bundle install --jobs=3 --retry=3 --path=vendor/bundle
21
+ ruby-version: ${{ matrix.ruby }}
22
+ bundler-cache: true
23
+
23
24
  - run: bundle exec rake
25
+ continue-on-error: ${{ matrix.allowed-failure }}
26
+ env:
27
+ LIQUID_C_PEDANTIC: 'true'
28
+ if: matrix.ruby != 'truffleruby-head'
29
+
30
+ - run: bundle exec rake test:unit
31
+ continue-on-error: ${{ matrix.allowed-failure }}
32
+ env:
33
+ LIQUID_C_PEDANTIC: 'true'
34
+ if: matrix.ruby == 'truffleruby-head'
35
+
36
+ - run: bundle exec rubocop
37
+ if: matrix.ruby != 'truffleruby-head'
38
+
39
+ valgrind:
40
+ runs-on: ubuntu-latest
41
+ steps:
42
+ - uses: actions/checkout@v2
43
+ - uses: ruby/setup-ruby@v1
44
+ with:
45
+ ruby-version: 3.3
46
+ bundler-cache: true
47
+ - run: sudo apt-get install -y valgrind
48
+ - run: bundle exec rake test:valgrind
data/.gitignore CHANGED
@@ -7,3 +7,7 @@ tmp
7
7
  *.bundle
8
8
  ext/*/Makefile
9
9
  *.so
10
+ instruments*.trace
11
+ *.cpu
12
+ *.object
13
+ *.dSYM
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ inherit_gem:
2
+ rubocop-shopify: rubocop.yml
3
+
4
+ require: rubocop-performance
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 2.5
8
+ Exclude:
9
+ - 'vendor/bundle/**/*'
10
+ - 'tmp/**/*'
11
+
12
+ Style/GlobalVars:
13
+ Exclude:
14
+ - 'ext/liquid_c/extconf.rb'
data/Gemfile CHANGED
@@ -1,14 +1,24 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ git_source(:github) do |repo_name|
5
+ "https://github.com/#{repo_name}.git"
6
+ end
2
7
 
3
8
  gemspec
4
9
 
5
- gem 'liquid', github: 'Shopify/liquid', branch: '4-0-stable'
10
+ gem "liquid", github: "Shopify/liquid", ref: "master"
6
11
 
7
12
  group :test do
8
- gem 'spy', '0.4.1'
9
- gem 'benchmark-ips'
13
+ gem "base64", require: false # for older rubocop on Ruby 3.4
14
+ gem "rubocop", "~> 1.24.1", require: false
15
+ gem "rubocop-performance", "~> 1.13.2", require: false
16
+ gem "rubocop-shopify", "~> 2.4.0", require: false
17
+ gem "spy", "0.4.1"
18
+ gem "benchmark-ips"
19
+ gem "ruby_memcheck"
10
20
  end
11
21
 
12
22
  group :development do
13
- gem 'byebug'
23
+ gem "byebug"
14
24
  end
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Liquid::C
2
- [![Build Status](https://travis-ci.org/Shopify/liquid-c.svg?branch=master)](https://travis-ci.org/Shopify/liquid-c)
2
+ [![Build Status](https://travis-ci.org/Shopify/liquid-c.svg?branch=main)](https://travis-ci.org/Shopify/liquid-c)
3
3
 
4
4
  Partial native implementation of the liquid ruby gem in C.
5
5
 
@@ -7,8 +7,8 @@ Partial native implementation of the liquid ruby gem in C.
7
7
 
8
8
  Add these lines to your application's Gemfile:
9
9
 
10
- gem 'liquid', github: 'Shopify/liquid', branch: 'master'
11
- gem 'liquid-c', github: 'Shopify/liquid-c', branch: 'master'
10
+ gem 'liquid', github: 'Shopify/liquid', branch: 'main'
11
+ gem 'liquid-c', github: 'Shopify/liquid-c', branch: 'main'
12
12
 
13
13
  And then execute:
14
14
 
@@ -31,14 +31,38 @@ then just use the documented API for the liquid Gem.
31
31
 
32
32
  To compare Liquid-C's performance with plain Liquid run
33
33
 
34
- bundle exec rake compare:run
34
+ bundle exec rake compare:lax
35
35
 
36
36
  The latest benchmark results are shown below:
37
37
 
38
- user system total real
39
- Liquid: 0.000000 0.000000 246.950000 (247.499526)
40
- Liquid-C: 0.000000 0.010000 224.270000 (224.794395)
41
- Ratio: 90.82619215891624%
38
+ ```
39
+ $ bundle exec rake compare:lax
40
+ /home/spin/.rubies/ruby-3.0.2/bin/ruby ./performance.rb bare benchmark lax
41
+
42
+ Running benchmark for 10 seconds (with 5 seconds warmup).
43
+
44
+ Warming up --------------------------------------
45
+ parse: 2.000 i/100ms
46
+ render: 8.000 i/100ms
47
+ parse & render: 2.000 i/100ms
48
+ Calculating -------------------------------------
49
+ parse: 29.527 (± 3.4%) i/s - 296.000 in 10.034520s
50
+ render: 89.403 (± 6.7%) i/s - 896.000 in 10.072939s
51
+ parse & render: 20.474 (± 4.9%) i/s - 206.000 in 10.072806s
52
+
53
+ /home/spin/.rubies/ruby-3.0.2/bin/ruby ./performance.rb c benchmark lax
54
+
55
+ Running benchmark for 10 seconds (with 5 seconds warmup).
56
+
57
+ Warming up --------------------------------------
58
+ parse: 10.000 i/100ms
59
+ render: 18.000 i/100ms
60
+ parse & render: 5.000 i/100ms
61
+ Calculating -------------------------------------
62
+ parse: 90.672 (± 3.3%) i/s - 910.000 in 10.051124s
63
+ render: 163.871 (± 4.9%) i/s - 1.638k in 10.018105s
64
+ parse & render: 50.165 (± 4.0%) i/s - 505.000 in 10.077377s
65
+ ```
42
66
 
43
67
  ## Developing
44
68
 
data/Rakefile CHANGED
@@ -1,69 +1,18 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'bundler/gem_tasks'
4
- require 'rake/extensiontask'
5
- require 'benchmark'
1
+ # frozen_string_literal: true
6
2
 
7
- ENV['DEBUG'] = 'true'
8
- Rake::ExtensionTask.new("liquid_c")
3
+ require "rake"
4
+ require "rake/testtask"
5
+ require "bundler/gem_tasks"
6
+ require "rake/extensiontask"
7
+ require "benchmark"
8
+ require "ruby_memcheck"
9
9
 
10
- task :default => :test
10
+ ENV["DEBUG"] ||= "true"
11
11
 
12
- task :test => ['test:unit', 'test:liquid']
12
+ task default: [:test, :rubocop]
13
13
 
14
- namespace :test do
15
- Rake::TestTask.new(:unit => :compile) do |t|
16
- t.libs << 'lib' << 'test'
17
- t.test_files = FileList['test/unit/**/*_test.rb']
18
- end
19
-
20
- desc 'run test suite with default parser'
21
- Rake::TestTask.new(:base_liquid => :compile) do |t|
22
- t.libs << 'lib'
23
- t.test_files = ['test/liquid_test.rb']
24
- end
25
-
26
- desc 'runs test suite with both strict and lax parsers'
27
- task :liquid do
28
- ENV['LIQUID_PARSER_MODE'] = 'lax'
29
- Rake::Task['test:base_liquid'].invoke
30
- ENV['LIQUID_PARSER_MODE'] = 'strict'
31
- Rake::Task['test:base_liquid'].reenable
32
- Rake::Task['test:base_liquid'].invoke
33
- end
34
- end
35
-
36
- namespace :benchmark do
37
- desc "Run the liquid benchmark with lax parsing"
38
- task :run do
39
- ruby "./performance.rb c benchmark lax"
40
- end
41
-
42
- desc "Run the liquid benchmark with strict parsing"
43
- task :strict do
44
- ruby "./performance.rb c benchmark strict"
45
- end
46
- end
47
-
48
-
49
- namespace :profile do
50
- desc "Run the liquid profile/performance coverage"
51
- task :run do
52
- ruby "./performance.rb c profile lax"
53
- end
14
+ task test: ["test:unit", "test:integration:all"]
54
15
 
55
- desc "Run the liquid profile/performance coverage with strict parsing"
56
- task :strict do
57
- ruby "./performance.rb c profile strict"
58
- end
59
- end
60
-
61
- namespace :compare do
62
- %w(lax warn strict).each do |type|
63
- desc "Compare Liquid to Liquid-C in #{type} mode"
64
- task type.to_sym do
65
- ruby "./performance.rb bare benchmark #{type}"
66
- ruby "./performance.rb c benchmark #{type}"
67
- end
68
- end
16
+ namespace :test do
17
+ task valgrind: ["test:unit:valgrind", "test:integration:valgrind:all"]
69
18
  end