liquid-c 4.0.1 → 4.1.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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/liquid.yml +24 -2
  3. data/.gitignore +4 -0
  4. data/.rubocop.yml +14 -0
  5. data/Gemfile +14 -5
  6. data/README.md +29 -5
  7. data/Rakefile +13 -62
  8. data/ext/liquid_c/block.c +488 -60
  9. data/ext/liquid_c/block.h +28 -2
  10. data/ext/liquid_c/c_buffer.c +42 -0
  11. data/ext/liquid_c/c_buffer.h +76 -0
  12. data/ext/liquid_c/context.c +233 -0
  13. data/ext/liquid_c/context.h +70 -0
  14. data/ext/liquid_c/document_body.c +89 -0
  15. data/ext/liquid_c/document_body.h +59 -0
  16. data/ext/liquid_c/expression.c +116 -0
  17. data/ext/liquid_c/expression.h +24 -0
  18. data/ext/liquid_c/extconf.rb +19 -9
  19. data/ext/liquid_c/intutil.h +22 -0
  20. data/ext/liquid_c/lexer.c +6 -2
  21. data/ext/liquid_c/lexer.h +18 -3
  22. data/ext/liquid_c/liquid.c +76 -6
  23. data/ext/liquid_c/liquid.h +24 -1
  24. data/ext/liquid_c/parse_context.c +76 -0
  25. data/ext/liquid_c/parse_context.h +13 -0
  26. data/ext/liquid_c/parser.c +141 -65
  27. data/ext/liquid_c/parser.h +4 -2
  28. data/ext/liquid_c/raw.c +110 -0
  29. data/ext/liquid_c/raw.h +6 -0
  30. data/ext/liquid_c/resource_limits.c +279 -0
  31. data/ext/liquid_c/resource_limits.h +23 -0
  32. data/ext/liquid_c/stringutil.h +44 -0
  33. data/ext/liquid_c/tokenizer.c +149 -35
  34. data/ext/liquid_c/tokenizer.h +20 -9
  35. data/ext/liquid_c/usage.c +18 -0
  36. data/ext/liquid_c/usage.h +9 -0
  37. data/ext/liquid_c/variable.c +196 -20
  38. data/ext/liquid_c/variable.h +18 -1
  39. data/ext/liquid_c/variable_lookup.c +44 -0
  40. data/ext/liquid_c/variable_lookup.h +8 -0
  41. data/ext/liquid_c/vm.c +588 -0
  42. data/ext/liquid_c/vm.h +25 -0
  43. data/ext/liquid_c/vm_assembler.c +491 -0
  44. data/ext/liquid_c/vm_assembler.h +240 -0
  45. data/ext/liquid_c/vm_assembler_pool.c +97 -0
  46. data/ext/liquid_c/vm_assembler_pool.h +27 -0
  47. data/lib/liquid/c/compile_ext.rb +44 -0
  48. data/lib/liquid/c/version.rb +3 -1
  49. data/lib/liquid/c.rb +225 -46
  50. data/liquid-c.gemspec +16 -10
  51. data/performance/c_profile.rb +23 -0
  52. data/performance.rb +6 -4
  53. data/rakelib/compile.rake +15 -0
  54. data/rakelib/integration_test.rake +43 -0
  55. data/rakelib/performance.rake +43 -0
  56. data/rakelib/rubocop.rake +6 -0
  57. data/rakelib/unit_test.rake +14 -0
  58. data/test/integration_test.rb +11 -0
  59. data/test/liquid_test_helper.rb +21 -0
  60. data/test/test_helper.rb +14 -2
  61. data/test/unit/block_test.rb +130 -0
  62. data/test/unit/context_test.rb +83 -0
  63. data/test/unit/expression_test.rb +186 -0
  64. data/test/unit/gc_stress_test.rb +28 -0
  65. data/test/unit/raw_test.rb +19 -0
  66. data/test/unit/resource_limits_test.rb +50 -0
  67. data/test/unit/tokenizer_test.rb +90 -20
  68. data/test/unit/variable_test.rb +212 -60
  69. metadata +59 -11
  70. 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: f0b1d438c8d9e73c713f3c66e14cc41a0b5351f33153047d46728a897c1bc576
4
+ data.tar.gz: 5275881737af08a486e1ebeb672333ffe534e0de20e8d018246013419950f382
5
5
  SHA512:
6
- metadata.gz: 9f6eb35fdd601a8ecc6d1f00beb3ef4d06ecb51c0de7fe5e9efbe9795d9ddc9828f5b0a4fe65cb719d91b322d3162a61e561c45b03f6cafebdc773a1f6bf2b7e
7
- data.tar.gz: d2c21226bb648cdd9b062997fede49f6b0a2bc8896c216c5e66554b4962cd9524fe0a09b25450f8a1ac76bce2cf7f61ccdec039bc35079ce28cb0770c4a6cfbf
6
+ metadata.gz: c21caebe56294b8ef4cce7712261c6f7a50ddb3fd72d08ad2463b7b561a8c13b2d0db1c9b3941ee3a8d4f9a816c85764db182b181a1eacf86032b6d27878e974
7
+ data.tar.gz: 736ebd21fd1cf147ed1f88cc3828a0209027d22cbec79f72f71fde2599523ec40e974b3ad1aa47acfd5724f4c0b1e3508ba74a13efee84e9e9771c39b012ef65
@@ -6,8 +6,10 @@ jobs:
6
6
  strategy:
7
7
  matrix:
8
8
  entry:
9
- - { ruby: 2.7 }
10
- - { ruby: 3.2 }
9
+ - { ruby: '2.5', allowed-failure: false }
10
+ - { ruby: '2.7', allowed-failure: false }
11
+ - { ruby: '3.0', allowed-failure: false }
12
+ - { ruby: ruby-head, allowed-failure: true }
11
13
  name: test (${{ matrix.entry.ruby }})
12
14
  steps:
13
15
  - uses: actions/checkout@v2
@@ -21,3 +23,23 @@ jobs:
21
23
  restore-keys: ${{ runner.os }}-gems-
22
24
  - run: bundle install --jobs=3 --retry=3 --path=vendor/bundle
23
25
  - run: bundle exec rake
26
+ continue-on-error: ${{ matrix.entry.allowed-failure }}
27
+ env:
28
+ LIQUID_C_PEDANTIC: 'true'
29
+ - run: bundle exec rubocop
30
+
31
+ valgrind:
32
+ runs-on: ubuntu-latest
33
+ steps:
34
+ - uses: actions/checkout@v2
35
+ - uses: ruby/setup-ruby@v1
36
+ with:
37
+ ruby-version: '3.0'
38
+ - run: sudo apt-get install -y valgrind
39
+ - uses: actions/cache@v1
40
+ with:
41
+ path: vendor/bundle
42
+ key: ${{ runner.os }}-gems-${{ hashFiles('Gemfile') }}
43
+ restore-keys: ${{ runner.os }}-gems-
44
+ - run: bundle install --jobs=3 --retry=3 --path=vendor/bundle
45
+ - 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,23 @@
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 "rubocop", "~> 1.24.1", require: false
14
+ gem "rubocop-performance", "~> 1.13.2", require: false
15
+ gem "rubocop-shopify", "~> 2.4.0", require: false
16
+ gem "spy", "0.4.1"
17
+ gem "benchmark-ips"
18
+ gem "ruby_memcheck"
10
19
  end
11
20
 
12
21
  group :development do
13
- gem 'byebug'
22
+ gem "byebug"
14
23
  end
data/README.md CHANGED
@@ -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,20 @@
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
+ RubyMemcheck.config(binary_name: "liquid_c")
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
14
+ task default: [:test, :rubocop]
41
15
 
42
- desc "Run the liquid benchmark with strict parsing"
43
- task :strict do
44
- ruby "./performance.rb c benchmark strict"
45
- end
46
- end
16
+ task test: ["test:unit", "test:integration:all"]
47
17
 
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
54
-
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
18
+ namespace :test do
19
+ task valgrind: ["test:unit:valgrind", "test:integration:valgrind:all"]
69
20
  end