panko_serializer 0.7.6 → 0.7.9
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.
- checksums.yaml +4 -4
 - data/.github/workflows/docs.yml +1 -1
 - data/.github/workflows/lint.yml +41 -0
 - data/.github/workflows/ruby.yml +35 -36
 - data/.standard.yml +4 -0
 - data/Gemfile +3 -2
 - data/Rakefile +12 -16
 - data/benchmarks/allocs.rb +1 -1
 - data/benchmarks/app.rb +1 -1
 - data/benchmarks/benchmarking_support.rb +3 -3
 - data/benchmarks/bm_ams_0_10.rb +2 -5
 - data/benchmarks/bm_object_writer.rb +1 -0
 - data/benchmarks/bm_panko_json.rb +1 -1
 - data/benchmarks/bm_panko_object.rb +1 -2
 - data/benchmarks/bm_plain_object.rb +7 -7
 - data/benchmarks/bm_serialization_descriptor.rb +5 -5
 - data/benchmarks/bm_serializer_resolver.rb +1 -0
 - data/benchmarks/bm_to_object.rb +2 -10
 - data/benchmarks/profile.rb +5 -7
 - data/benchmarks/sanity.rb +2 -10
 - data/benchmarks/setup.rb +2 -2
 - data/benchmarks/type_casts/bm_active_record.rb +6 -8
 - data/benchmarks/type_casts/bm_panko.rb +11 -11
 - data/benchmarks/type_casts/support.rb +6 -2
 - data/docs/docs/introduction.md +1 -1
 - data/docs/docs/performance.md +6 -6
 - data/docs/package-lock.json +12556 -168
 - data/ext/panko_serializer/attributes_writer/active_record.c +6 -6
 - data/ext/panko_serializer/attributes_writer/active_record.h +1 -2
 - data/ext/panko_serializer/attributes_writer/attributes_writer.c +5 -7
 - data/ext/panko_serializer/attributes_writer/attributes_writer.h +7 -2
 - data/ext/panko_serializer/attributes_writer/common.h +2 -1
 - data/ext/panko_serializer/attributes_writer/hash.c +3 -2
 - data/ext/panko_serializer/attributes_writer/hash.h +2 -4
 - data/ext/panko_serializer/attributes_writer/plain.c +2 -1
 - data/ext/panko_serializer/attributes_writer/plain.h +2 -4
 - data/ext/panko_serializer/attributes_writer/type_cast/type_cast.c +9 -9
 - data/ext/panko_serializer/attributes_writer/type_cast/type_cast.h +2 -3
 - data/ext/panko_serializer/common.h +0 -2
 - data/ext/panko_serializer/panko_serializer.c +6 -8
 - data/ext/panko_serializer/serialization_descriptor/association.c +1 -0
 - data/ext/panko_serializer/serialization_descriptor/association.h +1 -1
 - data/ext/panko_serializer/serialization_descriptor/attribute.c +1 -0
 - data/ext/panko_serializer/serialization_descriptor/attribute.h +2 -2
 - data/ext/panko_serializer/serialization_descriptor/serialization_descriptor.c +1 -1
 - data/ext/panko_serializer/serialization_descriptor/serialization_descriptor.h +1 -1
 - data/lib/panko/attribute.rb +5 -5
 - data/lib/panko/object_writer.rb +5 -1
 - data/lib/panko/response.rb +3 -3
 - data/lib/panko/serialization_descriptor.rb +2 -2
 - data/lib/panko/serializer.rb +8 -2
 - data/lib/panko/serializer_resolver.rb +7 -4
 - data/lib/panko/version.rb +1 -1
 - data/panko_serializer.gemspec +8 -8
 - metadata +5 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: c07649ad9566fb8f9ef1088a20bff7b93f76b5d6295d0505b81bca45ed47788c
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: a9d3736b9ef189d9087f036bcf9c4977ae950ffbb1e3dfb1386ec138fdcef101
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 609057962ee4975e8e392da3d762421e819f1bbac4d2511c156384732d9359922edd386d833353d112edea334f66c6a4f44f0dc593b16a8b1e62b2c64196f4df
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 18d84743b9f94f59db2bffd7716ecd6e796da1d3c135b401d5c8f0ae258f3c74276706794703d3841663add5cec70fee97ccbf54561688ee9247cdd11bc6d115
         
     | 
    
        data/.github/workflows/docs.yml
    CHANGED
    
    
| 
         @@ -0,0 +1,41 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            name: Lint
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            on: [push, pull_request]
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            jobs:
         
     | 
| 
      
 6 
     | 
    
         
            +
              build:
         
     | 
| 
      
 7 
     | 
    
         
            +
                runs-on: ubuntu-latest
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                steps:
         
     | 
| 
      
 10 
     | 
    
         
            +
                  - uses: actions/checkout@v2
         
     | 
| 
      
 11 
     | 
    
         
            +
                  - name: Set up Ruby
         
     | 
| 
      
 12 
     | 
    
         
            +
                    uses: ruby/setup-ruby@v1
         
     | 
| 
      
 13 
     | 
    
         
            +
                    with:
         
     | 
| 
      
 14 
     | 
    
         
            +
                      ruby-version: 3.1.0
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  - name: Install deps
         
     | 
| 
      
 17 
     | 
    
         
            +
                    run: |
         
     | 
| 
      
 18 
     | 
    
         
            +
                      sudo apt update -y
         
     | 
| 
      
 19 
     | 
    
         
            +
                      sudo apt install -y libsqlite3-dev
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                  - name: Install gems
         
     | 
| 
      
 22 
     | 
    
         
            +
                    env:
         
     | 
| 
      
 23 
     | 
    
         
            +
                      RAILS_VERSION: "7.0"
         
     | 
| 
      
 24 
     | 
    
         
            +
                    run: |
         
     | 
| 
      
 25 
     | 
    
         
            +
                      gem install bundler
         
     | 
| 
      
 26 
     | 
    
         
            +
                      bundle config set path 'vendor/bundle'
         
     | 
| 
      
 27 
     | 
    
         
            +
                      bundle check || bundle install --jobs 4 --retry 3
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                  - name: Lint ruby
         
     | 
| 
      
 30 
     | 
    
         
            +
                    env:
         
     | 
| 
      
 31 
     | 
    
         
            +
                      RAILS_VERSION: "7.0"
         
     | 
| 
      
 32 
     | 
    
         
            +
                    run: |
         
     | 
| 
      
 33 
     | 
    
         
            +
                      bundle exec rake standard
         
     | 
| 
      
 34 
     | 
    
         
            +
                      clang-format ext/**/*.{c,h}
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                  - name: Lint C
         
     | 
| 
      
 37 
     | 
    
         
            +
                    uses: jidicula/clang-format-action@v4.10.1
         
     | 
| 
      
 38 
     | 
    
         
            +
                    with:
         
     | 
| 
      
 39 
     | 
    
         
            +
                      clang-format-version: "15"
         
     | 
| 
      
 40 
     | 
    
         
            +
                      check-path: "ext/panko_serializer"
         
     | 
| 
      
 41 
     | 
    
         
            +
                      fallback-style: "Google"
         
     | 
    
        data/.github/workflows/ruby.yml
    CHANGED
    
    | 
         @@ -4,45 +4,44 @@ on: [push, pull_request] 
     | 
|
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            jobs:
         
     | 
| 
       6 
6 
     | 
    
         
             
              build:
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
7 
     | 
    
         
             
                runs-on: ubuntu-latest
         
     | 
| 
       9 
8 
     | 
    
         
             
                strategy:
         
     | 
| 
       10 
9 
     | 
    
         
             
                  fail-fast: false
         
     | 
| 
       11 
10 
     | 
    
         
             
                  matrix:
         
     | 
| 
       12 
     | 
    
         
            -
                    ruby: [ 
     | 
| 
       13 
     | 
    
         
            -
                    rails: [ 
     | 
| 
      
 11 
     | 
    
         
            +
                    ruby: ["2.7", "3.0", "3.1.0", "3.2.0"]
         
     | 
| 
      
 12 
     | 
    
         
            +
                    rails: ["6.0.0", "6.1.0", "7.0.0"]
         
     | 
| 
       14 
13 
     | 
    
         | 
| 
       15 
14 
     | 
    
         
             
                steps:
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
                  - uses: actions/checkout@v2
         
     | 
| 
      
 16 
     | 
    
         
            +
                  - name: Set up Ruby ${{ matrix.ruby }}
         
     | 
| 
      
 17 
     | 
    
         
            +
                    uses: ruby/setup-ruby@v1
         
     | 
| 
      
 18 
     | 
    
         
            +
                    with:
         
     | 
| 
      
 19 
     | 
    
         
            +
                      ruby-version: ${{ matrix.ruby }}
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                  - name: Install deps
         
     | 
| 
      
 22 
     | 
    
         
            +
                    run: |
         
     | 
| 
      
 23 
     | 
    
         
            +
                      sudo apt update -y
         
     | 
| 
      
 24 
     | 
    
         
            +
                      sudo apt install -y libsqlite3-dev
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  - name: Gems Cache
         
     | 
| 
      
 27 
     | 
    
         
            +
                    id: gem-cache
         
     | 
| 
      
 28 
     | 
    
         
            +
                    uses: actions/cache@v1
         
     | 
| 
      
 29 
     | 
    
         
            +
                    with:
         
     | 
| 
      
 30 
     | 
    
         
            +
                      path: vendor/bundle
         
     | 
| 
      
 31 
     | 
    
         
            +
                      key: ${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.rails }}-gem
         
     | 
| 
      
 32 
     | 
    
         
            +
                      restore-keys: |
         
     | 
| 
      
 33 
     | 
    
         
            +
                        ${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.rails }}-gem
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  - name: Install gems
         
     | 
| 
      
 36 
     | 
    
         
            +
                    env:
         
     | 
| 
      
 37 
     | 
    
         
            +
                      RAILS_VERSION: ${{ matrix.rails }}
         
     | 
| 
      
 38 
     | 
    
         
            +
                    run: |
         
     | 
| 
      
 39 
     | 
    
         
            +
                      gem install bundler
         
     | 
| 
      
 40 
     | 
    
         
            +
                      bundle config set path 'vendor/bundle'
         
     | 
| 
      
 41 
     | 
    
         
            +
                      bundle check || bundle install --jobs 4 --retry 3
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                  - name: Compile & test
         
     | 
| 
      
 44 
     | 
    
         
            +
                    env:
         
     | 
| 
      
 45 
     | 
    
         
            +
                      RAILS_VERSION: ${{ matrix.rails }}
         
     | 
| 
      
 46 
     | 
    
         
            +
                    run: |
         
     | 
| 
      
 47 
     | 
    
         
            +
                      bundle exec rake
         
     | 
    
        data/.standard.yml
    ADDED
    
    
    
        data/Gemfile
    CHANGED
    
    | 
         @@ -1,4 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            source "https://rubygems.org"
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
       4 
5 
     | 
    
         
             
            gemspec
         
     | 
| 
         @@ -10,7 +11,6 @@ gem "activesupport", rails_version 
     | 
|
| 
       10 
11 
     | 
    
         
             
            gem "activemodel", rails_version
         
     | 
| 
       11 
12 
     | 
    
         
             
            gem "activerecord", rails_version, group: :test
         
     | 
| 
       12 
13 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
14 
     | 
    
         
             
            group :benchmarks do
         
     | 
| 
       15 
15 
     | 
    
         
             
              gem "sqlite3", "~> 1.4"
         
     | 
| 
       16 
16 
     | 
    
         
             
              gem "pg", ">= 0.18", "< 2.0"
         
     | 
| 
         @@ -33,5 +33,6 @@ group :development do 
     | 
|
| 
       33 
33 
     | 
    
         
             
              gem "rake"
         
     | 
| 
       34 
34 
     | 
    
         
             
              gem "rspec", "~> 3.0"
         
     | 
| 
       35 
35 
     | 
    
         
             
              gem "rake-compiler"
         
     | 
| 
       36 
     | 
    
         
            -
              gem "rubocop"
         
     | 
| 
       37 
36 
     | 
    
         
             
            end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            gem "standard", group: [:development, :test]
         
     | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -1,13 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            require "bundler/gem_tasks"
         
     | 
| 
       3 
4 
     | 
    
         
             
            require "rspec/core/rake_task"
         
     | 
| 
       4 
5 
     | 
    
         
             
            require "json"
         
     | 
| 
       5 
6 
     | 
    
         
             
            require "terminal-table"
         
     | 
| 
       6 
7 
     | 
    
         
             
            require "rake/extensiontask"
         
     | 
| 
       7 
8 
     | 
    
         
             
            require "pty"
         
     | 
| 
      
 9 
     | 
    
         
            +
            require "standard/rake"
         
     | 
| 
       8 
10 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
            gem = Gem::Specification.load( 
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
            gem = Gem::Specification.load(File.dirname(__FILE__) + "/panko_serializer.gemspec")
         
     | 
| 
       11 
12 
     | 
    
         | 
| 
       12 
13 
     | 
    
         
             
            Rake::ExtensionTask.new("panko_serializer", gem) do |ext|
         
     | 
| 
       13 
14 
     | 
    
         
             
              ext.lib_dir = "lib/panko"
         
     | 
| 
         @@ -32,14 +33,12 @@ def run_process(cmd) 
     | 
|
| 
       32 
33 
     | 
    
         
             
              puts "> Running #{cmd}"
         
     | 
| 
       33 
34 
     | 
    
         
             
              lines = []
         
     | 
| 
       34 
35 
     | 
    
         
             
              PTY.spawn(cmd) do |stdout, stdin, pid|
         
     | 
| 
       35 
     | 
    
         
            -
                 
     | 
| 
       36 
     | 
    
         
            -
                   
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                    lines << line
         
     | 
| 
       39 
     | 
    
         
            -
                  end
         
     | 
| 
       40 
     | 
    
         
            -
                rescue Errno::EIO
         
     | 
| 
       41 
     | 
    
         
            -
                  # ignore this
         
     | 
| 
      
 36 
     | 
    
         
            +
                stdout.each do |line|
         
     | 
| 
      
 37 
     | 
    
         
            +
                  print_and_flush "."
         
     | 
| 
      
 38 
     | 
    
         
            +
                  lines << line
         
     | 
| 
       42 
39 
     | 
    
         
             
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
              rescue Errno::EIO
         
     | 
| 
      
 41 
     | 
    
         
            +
                # ignore this
         
     | 
| 
       43 
42 
     | 
    
         
             
              end
         
     | 
| 
       44 
43 
     | 
    
         | 
| 
       45 
44 
     | 
    
         
             
              lines
         
     | 
| 
         @@ -51,15 +50,12 @@ end 
     | 
|
| 
       51 
50 
     | 
    
         
             
            def run_benchmarks(files, items_count: 2_300)
         
     | 
| 
       52 
51 
     | 
    
         
             
              headings = ["Benchmark", "ip/s", "allocs/retained"]
         
     | 
| 
       53 
52 
     | 
    
         
             
              files.each do |benchmark_file|
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
53 
     | 
    
         
             
                lines = run_process "ITEMS_COUNT=#{items_count} RAILS_ENV=production ruby #{benchmark_file}"
         
     | 
| 
       56 
54 
     | 
    
         
             
                rows = lines.map do |line|
         
     | 
| 
       57 
     | 
    
         
            -
                   
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
                   
     | 
| 
       61 
     | 
    
         
            -
                    puts "> [ERROR] Failed running #{benchmark_file} - #{lines.join}"
         
     | 
| 
       62 
     | 
    
         
            -
                  end
         
     | 
| 
      
 55 
     | 
    
         
            +
                  row = JSON.parse(line)
         
     | 
| 
      
 56 
     | 
    
         
            +
                  row.values
         
     | 
| 
      
 57 
     | 
    
         
            +
                rescue JSON::ParserError
         
     | 
| 
      
 58 
     | 
    
         
            +
                  puts "> [ERROR] Failed running #{benchmark_file} - #{lines.join}"
         
     | 
| 
       63 
59 
     | 
    
         
             
                end
         
     | 
| 
       64 
60 
     | 
    
         | 
| 
       65 
61 
     | 
    
         
             
                puts "\n\n"
         
     | 
    
        data/benchmarks/allocs.rb
    CHANGED
    
    
    
        data/benchmarks/app.rb
    CHANGED
    
    
| 
         @@ -1,4 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            require "benchmark/ips"
         
     | 
| 
       3 
4 
     | 
    
         
             
            require "json"
         
     | 
| 
       4 
5 
     | 
    
         
             
            require "memory_profiler"
         
     | 
| 
         @@ -8,11 +9,11 @@ module Benchmark 
     | 
|
| 
       8 
9 
     | 
    
         
             
                def data
         
     | 
| 
       9 
10 
     | 
    
         
             
                  posts = Post.all.includes(:author).to_a
         
     | 
| 
       10 
11 
     | 
    
         
             
                  posts_50 = posts.first(50).to_a
         
     | 
| 
       11 
     | 
    
         
            -
                  { 
     | 
| 
      
 12 
     | 
    
         
            +
                  {all: posts, small: posts_50}
         
     | 
| 
       12 
13 
     | 
    
         
             
                end
         
     | 
| 
       13 
14 
     | 
    
         | 
| 
       14 
15 
     | 
    
         
             
                def run(label = nil, time: 10, disable_gc: true, warmup: 3, &block)
         
     | 
| 
       15 
     | 
    
         
            -
                  fail ArgumentError.new, "block should be passed" unless  
     | 
| 
      
 16 
     | 
    
         
            +
                  fail ArgumentError.new, "block should be passed" unless block
         
     | 
| 
       16 
17 
     | 
    
         | 
| 
       17 
18 
     | 
    
         
             
                  GC.start
         
     | 
| 
       18 
19 
     | 
    
         | 
| 
         @@ -35,7 +36,6 @@ module Benchmark 
     | 
|
| 
       35 
36 
     | 
    
         
             
                  }.to_json
         
     | 
| 
       36 
37 
     | 
    
         | 
| 
       37 
38 
     | 
    
         
             
                  puts results
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
39 
     | 
    
         
             
                end
         
     | 
| 
       40 
40 
     | 
    
         
             
              end
         
     | 
| 
       41 
41 
     | 
    
         | 
    
        data/benchmarks/bm_ams_0_10.rb
    CHANGED
    
    | 
         @@ -1,11 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            require_relative "./benchmarking_support"
         
     | 
| 
       3 
4 
     | 
    
         
             
            require_relative "./app"
         
     | 
| 
       4 
5 
     | 
    
         
             
            require_relative "./setup"
         
     | 
| 
       5 
6 
     | 
    
         | 
| 
       6 
7 
     | 
    
         
             
            # disable logging for benchmarks
         
     | 
| 
       7 
     | 
    
         
            -
            ActiveModelSerializers.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new( 
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 8 
     | 
    
         
            +
            ActiveModelSerializers.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new("/dev/null"))
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
            class AmsAuthorFastSerializer < ActiveModel::Serializer
         
     | 
| 
       11 
11 
     | 
    
         
             
              attributes :id, :name
         
     | 
| 
         @@ -28,7 +28,6 @@ def benchmark_ams(prefix, serializer, options = {}) 
     | 
|
| 
       28 
28 
     | 
    
         
             
              posts = data[:all]
         
     | 
| 
       29 
29 
     | 
    
         
             
              posts_50 = data[:small]
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
31 
     | 
    
         
             
              Benchmark.run("AMS_#{prefix}_Posts_#{posts.count}") do
         
     | 
| 
       33 
32 
     | 
    
         
             
                ActiveModelSerializers::SerializableResource.new(posts, merged_options).to_json
         
     | 
| 
       34 
33 
     | 
    
         
             
              end
         
     | 
| 
         @@ -42,9 +41,7 @@ def benchmark_ams(prefix, serializer, options = {}) 
     | 
|
| 
       42 
41 
     | 
    
         
             
              end
         
     | 
| 
       43 
42 
     | 
    
         
             
            end
         
     | 
| 
       44 
43 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
44 
     | 
    
         
             
            benchmark_ams "Attributes_Simple", AmsPostFastSerializer
         
     | 
| 
       47 
45 
     | 
    
         
             
            benchmark_ams "Attributes_HasOne", AmsPostWithHasOneFastSerializer
         
     | 
| 
       48 
46 
     | 
    
         
             
            benchmark_ams "Attributes_Except", AmsPostWithHasOneFastSerializer, except: [:title]
         
     | 
| 
       49 
47 
     | 
    
         
             
            benchmark_ams "Attributes_Only", AmsPostWithHasOneFastSerializer, only: [:id, :body, :author_id, :author]
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
    
        data/benchmarks/bm_panko_json.rb
    CHANGED
    
    | 
         @@ -1,4 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            require_relative "./benchmarking_support"
         
     | 
| 
       3 
4 
     | 
    
         
             
            require_relative "./app"
         
     | 
| 
       4 
5 
     | 
    
         
             
            require_relative "./setup"
         
     | 
| 
         @@ -7,7 +8,6 @@ class AuthorFastSerializer < Panko::Serializer 
     | 
|
| 
       7 
8 
     | 
    
         
             
              attributes :id, :name
         
     | 
| 
       8 
9 
     | 
    
         
             
            end
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
11 
     | 
    
         
             
            class PostFastSerializer < Panko::Serializer
         
     | 
| 
       12 
12 
     | 
    
         
             
              attributes :id, :body, :title, :author_id, :created_at
         
     | 
| 
       13 
13 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,4 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            require_relative "./benchmarking_support"
         
     | 
| 
       3 
4 
     | 
    
         
             
            require_relative "./app"
         
     | 
| 
       4 
5 
     | 
    
         
             
            require_relative "./setup"
         
     | 
| 
         @@ -7,7 +8,6 @@ class AuthorFastSerializer < Panko::Serializer 
     | 
|
| 
       7 
8 
     | 
    
         
             
              attributes :id, :name
         
     | 
| 
       8 
9 
     | 
    
         
             
            end
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
11 
     | 
    
         
             
            class PostFastSerializer < Panko::Serializer
         
     | 
| 
       12 
12 
     | 
    
         
             
              attributes :id, :body, :title, :author_id
         
     | 
| 
       13 
13 
     | 
    
         
             
            end
         
     | 
| 
         @@ -24,7 +24,6 @@ class AuthorWithHasManyFastSerializer < Panko::Serializer 
     | 
|
| 
       24 
24 
     | 
    
         
             
              has_many :posts, serializer: PostFastSerializer
         
     | 
| 
       25 
25 
     | 
    
         
             
            end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
27 
     | 
    
         
             
            def benchmark(prefix, serializer, options = {})
         
     | 
| 
       29 
28 
     | 
    
         
             
              data = Benchmark.data
         
     | 
| 
       30 
29 
     | 
    
         
             
              posts = data[:all]
         
     | 
| 
         @@ -1,4 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            require_relative "./benchmarking_support"
         
     | 
| 
       3 
4 
     | 
    
         
             
            require_relative "./app"
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
         @@ -6,7 +7,6 @@ class AuthorFastSerializer < Panko::Serializer 
     | 
|
| 
       6 
7 
     | 
    
         
             
              attributes :id, :name
         
     | 
| 
       7 
8 
     | 
    
         
             
            end
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
10 
     | 
    
         
             
            class PostFastSerializer < Panko::Serializer
         
     | 
| 
       11 
11 
     | 
    
         
             
              attributes :id, :body, :title, :author_id, :created_at
         
     | 
| 
       12 
12 
     | 
    
         
             
            end
         
     | 
| 
         @@ -32,11 +32,12 @@ class AuthorWithHasManyFastSerializer < Panko::Serializer 
     | 
|
| 
       32 
32 
     | 
    
         
             
            end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
            class Post
         
     | 
| 
       35 
     | 
    
         
            -
              attr_accessor :id, :body, :title, :created_at, : 
     | 
| 
      
 35 
     | 
    
         
            +
              attr_accessor :id, :body, :title, :created_at, :author_id
         
     | 
| 
      
 36 
     | 
    
         
            +
              attr_reader :author
         
     | 
| 
       36 
37 
     | 
    
         | 
| 
       37 
38 
     | 
    
         
             
              def self.create(attrs)
         
     | 
| 
       38 
39 
     | 
    
         
             
                p = Post.new
         
     | 
| 
       39 
     | 
    
         
            -
                attrs.each do |k,v|
         
     | 
| 
      
 40 
     | 
    
         
            +
                attrs.each do |k, v|
         
     | 
| 
       40 
41 
     | 
    
         
             
                  p.send :"#{k}=", v
         
     | 
| 
       41 
42 
     | 
    
         
             
                end
         
     | 
| 
       42 
43 
     | 
    
         
             
                p
         
     | 
| 
         @@ -44,7 +45,7 @@ class Post 
     | 
|
| 
       44 
45 
     | 
    
         | 
| 
       45 
46 
     | 
    
         
             
              def author=(author)
         
     | 
| 
       46 
47 
     | 
    
         
             
                @author = author
         
     | 
| 
       47 
     | 
    
         
            -
                @author_id =  
     | 
| 
      
 48 
     | 
    
         
            +
                @author_id = author.id
         
     | 
| 
       48 
49 
     | 
    
         
             
              end
         
     | 
| 
       49 
50 
     | 
    
         
             
            end
         
     | 
| 
       50 
51 
     | 
    
         | 
| 
         @@ -53,7 +54,7 @@ class Author 
     | 
|
| 
       53 
54 
     | 
    
         | 
| 
       54 
55 
     | 
    
         
             
              def self.create(attrs)
         
     | 
| 
       55 
56 
     | 
    
         
             
                a = Author.new
         
     | 
| 
       56 
     | 
    
         
            -
                attrs.each do |k,v|
         
     | 
| 
      
 57 
     | 
    
         
            +
                attrs.each do |k, v|
         
     | 
| 
       57 
58 
     | 
    
         
             
                  a.send :"#{k}=", v
         
     | 
| 
       58 
59 
     | 
    
         
             
                end
         
     | 
| 
       59 
60 
     | 
    
         
             
                a
         
     | 
| 
         @@ -71,10 +72,9 @@ def benchmark_data 
     | 
|
| 
       71 
72 
     | 
    
         
             
                )
         
     | 
| 
       72 
73 
     | 
    
         
             
              end
         
     | 
| 
       73 
74 
     | 
    
         | 
| 
       74 
     | 
    
         
            -
              { 
     | 
| 
      
 75 
     | 
    
         
            +
              {all: posts, small: posts.first(50)}
         
     | 
| 
       75 
76 
     | 
    
         
             
            end
         
     | 
| 
       76 
77 
     | 
    
         | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
78 
     | 
    
         
             
            def benchmark(prefix, serializer, options = {})
         
     | 
| 
       79 
79 
     | 
    
         
             
              data = benchmark_data
         
     | 
| 
       80 
80 
     | 
    
         
             
              posts = data[:all]
         
     | 
| 
         @@ -1,4 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            require_relative "./benchmarking_support"
         
     | 
| 
       3 
4 
     | 
    
         
             
            require "active_support"
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
         @@ -9,15 +10,15 @@ def generate_attributes(count) 
     | 
|
| 
       9 
10 
     | 
    
         
             
            end
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
       11 
12 
     | 
    
         
             
            class LeafASerializer < Panko::Serializer
         
     | 
| 
       12 
     | 
    
         
            -
              attributes 
     | 
| 
      
 13 
     | 
    
         
            +
              attributes(*generate_attributes(5))
         
     | 
| 
       13 
14 
     | 
    
         
             
            end
         
     | 
| 
       14 
15 
     | 
    
         | 
| 
       15 
16 
     | 
    
         
             
            class LeafBSerializer < Panko::Serializer
         
     | 
| 
       16 
     | 
    
         
            -
              attributes 
     | 
| 
      
 17 
     | 
    
         
            +
              attributes(*generate_attributes(6))
         
     | 
| 
       17 
18 
     | 
    
         
             
            end
         
     | 
| 
       18 
19 
     | 
    
         | 
| 
       19 
20 
     | 
    
         
             
            class ChildrenSerializer < Panko::Serializer
         
     | 
| 
       20 
     | 
    
         
            -
              attributes 
     | 
| 
      
 21 
     | 
    
         
            +
              attributes(*generate_attributes(28))
         
     | 
| 
       21 
22 
     | 
    
         | 
| 
       22 
23 
     | 
    
         
             
              has_one :leaf_a, serializer: LeafASerializer
         
     | 
| 
       23 
24 
     | 
    
         
             
              has_one :leaf_b, serializer: LeafBSerializer
         
     | 
| 
         @@ -39,11 +40,10 @@ class ChildrenSerializer < Panko::Serializer 
     | 
|
| 
       39 
40 
     | 
    
         
             
            end
         
     | 
| 
       40 
41 
     | 
    
         | 
| 
       41 
42 
     | 
    
         
             
            class ParentSerializer < Panko::Serializer
         
     | 
| 
       42 
     | 
    
         
            -
              attributes 
     | 
| 
      
 43 
     | 
    
         
            +
              attributes(*generate_attributes(46))
         
     | 
| 
       43 
44 
     | 
    
         | 
| 
       44 
45 
     | 
    
         
             
              has_many :children, serializer: ChildrenSerializer
         
     | 
| 
       45 
46 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
47 
     | 
    
         
             
              def attr_1
         
     | 
| 
       48 
48 
     | 
    
         
             
              end
         
     | 
| 
       49 
49 
     | 
    
         | 
    
        data/benchmarks/bm_to_object.rb
    CHANGED
    
    | 
         @@ -1,10 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            require_relative "./benchmarking_support"
         
     | 
| 
       3 
4 
     | 
    
         
             
            require_relative "./app"
         
     | 
| 
       4 
5 
     | 
    
         
             
            require_relative "./setup"
         
     | 
| 
       5 
6 
     | 
    
         | 
| 
       6 
7 
     | 
    
         
             
            class PostWithAliasModel < ActiveRecord::Base
         
     | 
| 
       7 
     | 
    
         
            -
              self.table_name =  
     | 
| 
      
 8 
     | 
    
         
            +
              self.table_name = "posts"
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
10 
     | 
    
         
             
              alias_attribute :new_id, :id
         
     | 
| 
       10 
11 
     | 
    
         
             
              alias_attribute :new_body, :body
         
     | 
| 
         @@ -20,7 +21,6 @@ end 
     | 
|
| 
       20 
21 
     | 
    
         
             
            def benchmark_aliased(prefix, serializer, options = {})
         
     | 
| 
       21 
22 
     | 
    
         
             
              posts = PostWithAliasModel.all.to_a
         
     | 
| 
       22 
23 
     | 
    
         
             
              posts_50 = posts.first(50).to_a
         
     | 
| 
       23 
     | 
    
         
            -
              data = { all: posts, small: posts_50 }
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
              merged_options = options.merge(each_serializer: serializer)
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
         @@ -28,10 +28,6 @@ def benchmark_aliased(prefix, serializer, options = {}) 
     | 
|
| 
       28 
28 
     | 
    
         
             
                Panko::ArraySerializer.new(posts, merged_options).to_json
         
     | 
| 
       29 
29 
     | 
    
         
             
              end
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
              posts = PostWithAliasModel.all.to_a
         
     | 
| 
       32 
     | 
    
         
            -
              posts_50 = posts.first(50).to_a
         
     | 
| 
       33 
     | 
    
         
            -
              data = { all: posts, small: posts_50 }
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
31 
     | 
    
         
             
              Benchmark.run("Panko_#{prefix}_Posts_50") do
         
     | 
| 
       36 
32 
     | 
    
         
             
                Panko::ArraySerializer.new(posts_50, merged_options).to_json
         
     | 
| 
       37 
33 
     | 
    
         
             
              end
         
     | 
| 
         @@ -41,7 +37,6 @@ class AuthorFastSerializer < Panko::Serializer 
     | 
|
| 
       41 
37 
     | 
    
         
             
              attributes :id, :name
         
     | 
| 
       42 
38 
     | 
    
         
             
            end
         
     | 
| 
       43 
39 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
40 
     | 
    
         
             
            class PostFastSerializer < Panko::Serializer
         
     | 
| 
       46 
41 
     | 
    
         
             
              attributes :id, :body, :title, :author_id, :created_at
         
     | 
| 
       47 
42 
     | 
    
         
             
            end
         
     | 
| 
         @@ -66,7 +61,6 @@ class AuthorWithHasManyFastSerializer < Panko::Serializer 
     | 
|
| 
       66 
61 
     | 
    
         
             
              has_many :posts, serializer: PostFastSerializer
         
     | 
| 
       67 
62 
     | 
    
         
             
            end
         
     | 
| 
       68 
63 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
64 
     | 
    
         
             
            def benchmark(prefix, serializer, options = {})
         
     | 
| 
       71 
65 
     | 
    
         
             
              data = Benchmark.data
         
     | 
| 
       72 
66 
     | 
    
         
             
              posts = data[:all]
         
     | 
| 
         @@ -87,7 +81,5 @@ def benchmark(prefix, serializer, options = {}) 
     | 
|
| 
       87 
81 
     | 
    
         
             
              end
         
     | 
| 
       88 
82 
     | 
    
         
             
            end
         
     | 
| 
       89 
83 
     | 
    
         | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
84 
     | 
    
         
             
            benchmark "Simple", PostFastSerializer
         
     | 
| 
       93 
85 
     | 
    
         
             
            benchmark "HasOne", PostWithHasOneFastSerializer
         
     | 
    
        data/benchmarks/profile.rb
    CHANGED
    
    | 
         @@ -1,4 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            require_relative "./benchmarking_support"
         
     | 
| 
       3 
4 
     | 
    
         
             
            require_relative "./app"
         
     | 
| 
       4 
5 
     | 
    
         
             
            require_relative "./setup"
         
     | 
| 
         @@ -22,7 +23,7 @@ class BenchmarkApp < Rails::Application 
     | 
|
| 
       22 
23 
     | 
    
         
             
                get "/serialize_to_stream" => "streaming#serialize_to_stream"
         
     | 
| 
       23 
24 
     | 
    
         
             
              end
         
     | 
| 
       24 
25 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
              config.secret_token = "s"*30
         
     | 
| 
      
 26 
     | 
    
         
            +
              config.secret_token = "s" * 30
         
     | 
| 
       26 
27 
     | 
    
         
             
              config.secret_key_base = "foo"
         
     | 
| 
       27 
28 
     | 
    
         
             
              config.consider_all_requests_local = false
         
     | 
| 
       28 
29 
     | 
    
         | 
| 
         @@ -55,7 +56,7 @@ class StreamingController < ActionController::Base 
     | 
|
| 
       55 
56 
     | 
    
         
             
              include ActionController::Live
         
     | 
| 
       56 
57 
     | 
    
         | 
| 
       57 
58 
     | 
    
         
             
              def serialize_to_stream
         
     | 
| 
       58 
     | 
    
         
            -
                headers["Content-Type" 
     | 
| 
      
 59 
     | 
    
         
            +
                headers["Content-Type"] = "application/json"
         
     | 
| 
       59 
60 
     | 
    
         | 
| 
       60 
61 
     | 
    
         
             
                data = Benchmark.data[:all]
         
     | 
| 
       61 
62 
     | 
    
         
             
                serializer = Panko::ArraySerializer.new([], each_serializer: PostWithHasOneFastSerializer)
         
     | 
| 
         @@ -67,19 +68,16 @@ class StreamingController < ActionController::Base 
     | 
|
| 
       67 
68 
     | 
    
         
             
              end
         
     | 
| 
       68 
69 
     | 
    
         
             
            end
         
     | 
| 
       69 
70 
     | 
    
         | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
            class RouteNotFoundError < StandardError;end
         
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
      
 71 
     | 
    
         
            +
            class RouteNotFoundError < StandardError; end
         
     | 
| 
       73 
72 
     | 
    
         | 
| 
       74 
73 
     | 
    
         
             
            def request(method, path)
         
     | 
| 
       75 
74 
     | 
    
         
             
              response = Rack::MockRequest.new(BenchmarkApp).send(method, path)
         
     | 
| 
       76 
75 
     | 
    
         
             
              if response.status.in?([404, 500])
         
     | 
| 
       77 
     | 
    
         
            -
                raise RouteNotFoundError.new,  
     | 
| 
      
 76 
     | 
    
         
            +
                raise RouteNotFoundError.new, "not found #{method.to_s.upcase} #{path}"
         
     | 
| 
       78 
77 
     | 
    
         
             
              end
         
     | 
| 
       79 
78 
     | 
    
         
             
              response
         
     | 
| 
       80 
79 
     | 
    
         
             
            end
         
     | 
| 
       81 
80 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
81 
     | 
    
         
             
            def memory(&block)
         
     | 
| 
       84 
82 
     | 
    
         
             
              mem = MemoryProfiler.report(&block)
         
     | 
| 
       85 
83 
     | 
    
         
             
              mem.pretty_print
         
     | 
    
        data/benchmarks/sanity.rb
    CHANGED
    
    | 
         @@ -1,10 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            require_relative "./benchmarking_support"
         
     | 
| 
       3 
4 
     | 
    
         
             
            require_relative "./app"
         
     | 
| 
       4 
5 
     | 
    
         
             
            require_relative "./setup"
         
     | 
| 
       5 
6 
     | 
    
         | 
| 
       6 
7 
     | 
    
         
             
            class PostWithAliasModel < ActiveRecord::Base
         
     | 
| 
       7 
     | 
    
         
            -
              self.table_name =  
     | 
| 
      
 8 
     | 
    
         
            +
              self.table_name = "posts"
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
10 
     | 
    
         
             
              alias_attribute :new_id, :id
         
     | 
| 
       10 
11 
     | 
    
         
             
              alias_attribute :new_body, :body
         
     | 
| 
         @@ -20,7 +21,6 @@ end 
     | 
|
| 
       20 
21 
     | 
    
         
             
            def benchmark_aliased(prefix, serializer, options = {})
         
     | 
| 
       21 
22 
     | 
    
         
             
              posts = PostWithAliasModel.all.to_a
         
     | 
| 
       22 
23 
     | 
    
         
             
              posts_50 = posts.first(50).to_a
         
     | 
| 
       23 
     | 
    
         
            -
              data = { all: posts, small: posts_50 }
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
              merged_options = options.merge(each_serializer: serializer)
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
         @@ -28,10 +28,6 @@ def benchmark_aliased(prefix, serializer, options = {}) 
     | 
|
| 
       28 
28 
     | 
    
         
             
                Panko::ArraySerializer.new(posts, merged_options).to_json
         
     | 
| 
       29 
29 
     | 
    
         
             
              end
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
              posts = PostWithAliasModel.all.to_a
         
     | 
| 
       32 
     | 
    
         
            -
              posts_50 = posts.first(50).to_a
         
     | 
| 
       33 
     | 
    
         
            -
              data = { all: posts, small: posts_50 }
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
31 
     | 
    
         
             
              Benchmark.run("Panko_#{prefix}_Posts_50") do
         
     | 
| 
       36 
32 
     | 
    
         
             
                Panko::ArraySerializer.new(posts_50, merged_options).to_json
         
     | 
| 
       37 
33 
     | 
    
         
             
              end
         
     | 
| 
         @@ -41,7 +37,6 @@ class AuthorFastSerializer < Panko::Serializer 
     | 
|
| 
       41 
37 
     | 
    
         
             
              attributes :id, :name
         
     | 
| 
       42 
38 
     | 
    
         
             
            end
         
     | 
| 
       43 
39 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
40 
     | 
    
         
             
            class PostFastSerializer < Panko::Serializer
         
     | 
| 
       46 
41 
     | 
    
         
             
              attributes :id, :body, :title, :author_id, :created_at
         
     | 
| 
       47 
42 
     | 
    
         
             
            end
         
     | 
| 
         @@ -66,7 +61,6 @@ class AuthorWithHasManyFastSerializer < Panko::Serializer 
     | 
|
| 
       66 
61 
     | 
    
         
             
              has_many :posts, serializer: PostFastSerializer
         
     | 
| 
       67 
62 
     | 
    
         
             
            end
         
     | 
| 
       68 
63 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
64 
     | 
    
         
             
            def benchmark(prefix, serializer, options = {})
         
     | 
| 
       71 
65 
     | 
    
         
             
              data = Benchmark.data
         
     | 
| 
       72 
66 
     | 
    
         
             
              posts = data[:all]
         
     | 
| 
         @@ -87,8 +81,6 @@ def benchmark(prefix, serializer, options = {}) 
     | 
|
| 
       87 
81 
     | 
    
         
             
              end
         
     | 
| 
       88 
82 
     | 
    
         
             
            end
         
     | 
| 
       89 
83 
     | 
    
         | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
84 
     | 
    
         
             
            benchmark "Simple", PostFastSerializer
         
     | 
| 
       93 
85 
     | 
    
         
             
            benchmark "HasOne", PostWithHasOneFastSerializer
         
     | 
| 
       94 
86 
     | 
    
         
             
            benchmark "SimpleWithMethodCall", PostFastWithMethodCallSerializer
         
     | 
    
        data/benchmarks/setup.rb
    CHANGED
    
    | 
         @@ -1,11 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            ###########################################
         
     | 
| 
       3 
4 
     | 
    
         
             
            # Setup active record models
         
     | 
| 
       4 
5 
     | 
    
         
             
            ##########################################
         
     | 
| 
       5 
6 
     | 
    
         
             
            require "active_record"
         
     | 
| 
       6 
7 
     | 
    
         
             
            require "sqlite3"
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
9 
     | 
    
         
             
            # Change the following to reflect your database settings
         
     | 
| 
       10 
10 
     | 
    
         
             
            ActiveRecord::Base.establish_connection(
         
     | 
| 
       11 
11 
     | 
    
         
             
              adapter: "sqlite3",
         
     | 
| 
         @@ -49,7 +49,7 @@ Post.transaction do 
     | 
|
| 
       49 
49 
     | 
    
         
             
                  body: "something about how password restrictions are evil, and less secure, and with the math to prove it.",
         
     | 
| 
       50 
50 
     | 
    
         
             
                  title: "Your bank is does not know how to do security",
         
     | 
| 
       51 
51 
     | 
    
         
             
                  author: Author.create(name: "Preston Sego"),
         
     | 
| 
       52 
     | 
    
         
            -
                  data: { 
     | 
| 
      
 52 
     | 
    
         
            +
                  data: {a: 1, b: 2, c: 3}
         
     | 
| 
       53 
53 
     | 
    
         
             
                )
         
     | 
| 
       54 
54 
     | 
    
         
             
              end
         
     | 
| 
       55 
55 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,4 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            require_relative "./support"
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
       4 
5 
     | 
    
         
             
            def ar_type_convert(type_klass, from, to)
         
     | 
| 
         @@ -28,9 +29,9 @@ def ar_type_convert(type_klass, from, to) 
     | 
|
| 
       28 
29 
     | 
    
         
             
            end
         
     | 
| 
       29 
30 
     | 
    
         | 
| 
       30 
31 
     | 
    
         
             
            def utc_ar_time
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
      
 32 
     | 
    
         
            +
              date = DateTime.new(2017, 3, 4, 12, 45, 23)
         
     | 
| 
      
 33 
     | 
    
         
            +
              tz = ActiveSupport::TimeZone.new("UTC")
         
     | 
| 
      
 34 
     | 
    
         
            +
              from = date.in_time_zone(tz).iso8601
         
     | 
| 
       34 
35 
     | 
    
         | 
| 
       35 
36 
     | 
    
         
             
              type = ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateTime.new
         
     | 
| 
       36 
37 
     | 
    
         
             
              converter = ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter.new(type)
         
     | 
| 
         @@ -46,15 +47,12 @@ def utc_ar_time 
     | 
|
| 
       46 
47 
     | 
    
         
             
              end
         
     | 
| 
       47 
48 
     | 
    
         
             
            end
         
     | 
| 
       48 
49 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
50 
     | 
    
         
             
            def db_ar_time
         
     | 
| 
       52 
51 
     | 
    
         
             
              type = ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateTime.new
         
     | 
| 
       53 
52 
     | 
    
         
             
              converter = ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter.new(type)
         
     | 
| 
       54 
53 
     | 
    
         | 
| 
       55 
54 
     | 
    
         
             
              from = "2017-07-10 09:26:40.937392"
         
     | 
| 
       56 
55 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
56 
     | 
    
         
             
              if ENV["RAILS_VERSION"].start_with? "4.2"
         
     | 
| 
       59 
57 
     | 
    
         
             
                Benchmark.run("ActiveRecord_Time_TypeCast_WithISO8601") do
         
     | 
| 
       60 
58 
     | 
    
         
             
                  converter.type_cast_from_database(from).iso8601
         
     | 
| 
         @@ -79,10 +77,10 @@ if ENV["RAILS_VERSION"].start_with? "4.2" 
     | 
|
| 
       79 
77 
     | 
    
         
             
              ar_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Float, "Infinity", ::Float::INFINITY
         
     | 
| 
       80 
78 
     | 
    
         
             
            end
         
     | 
| 
       81 
79 
     | 
    
         
             
            if check_if_exists "ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json"
         
     | 
| 
       82 
     | 
    
         
            -
              ar_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json, '{"a":1}', {a:1}
         
     | 
| 
      
 80 
     | 
    
         
            +
              ar_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json, '{"a":1}', {a: 1}
         
     | 
| 
       83 
81 
     | 
    
         
             
            end
         
     | 
| 
       84 
82 
     | 
    
         
             
            if check_if_exists "ActiveRecord::Type::Json"
         
     | 
| 
       85 
     | 
    
         
            -
              ar_type_convert ActiveRecord::Type::Json, '{"a":1}', {a:1}
         
     | 
| 
      
 83 
     | 
    
         
            +
              ar_type_convert ActiveRecord::Type::Json, '{"a":1}', {a: 1}
         
     | 
| 
       86 
84 
     | 
    
         
             
            end
         
     | 
| 
       87 
85 
     | 
    
         | 
| 
       88 
86 
     | 
    
         
             
            db_ar_time
         
     |