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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/docs.yml +1 -1
  3. data/.github/workflows/lint.yml +41 -0
  4. data/.github/workflows/ruby.yml +35 -36
  5. data/.standard.yml +4 -0
  6. data/Gemfile +3 -2
  7. data/Rakefile +12 -16
  8. data/benchmarks/allocs.rb +1 -1
  9. data/benchmarks/app.rb +1 -1
  10. data/benchmarks/benchmarking_support.rb +3 -3
  11. data/benchmarks/bm_ams_0_10.rb +2 -5
  12. data/benchmarks/bm_object_writer.rb +1 -0
  13. data/benchmarks/bm_panko_json.rb +1 -1
  14. data/benchmarks/bm_panko_object.rb +1 -2
  15. data/benchmarks/bm_plain_object.rb +7 -7
  16. data/benchmarks/bm_serialization_descriptor.rb +5 -5
  17. data/benchmarks/bm_serializer_resolver.rb +1 -0
  18. data/benchmarks/bm_to_object.rb +2 -10
  19. data/benchmarks/profile.rb +5 -7
  20. data/benchmarks/sanity.rb +2 -10
  21. data/benchmarks/setup.rb +2 -2
  22. data/benchmarks/type_casts/bm_active_record.rb +6 -8
  23. data/benchmarks/type_casts/bm_panko.rb +11 -11
  24. data/benchmarks/type_casts/support.rb +6 -2
  25. data/docs/docs/introduction.md +1 -1
  26. data/docs/docs/performance.md +6 -6
  27. data/docs/package-lock.json +12556 -168
  28. data/ext/panko_serializer/attributes_writer/active_record.c +6 -6
  29. data/ext/panko_serializer/attributes_writer/active_record.h +1 -2
  30. data/ext/panko_serializer/attributes_writer/attributes_writer.c +5 -7
  31. data/ext/panko_serializer/attributes_writer/attributes_writer.h +7 -2
  32. data/ext/panko_serializer/attributes_writer/common.h +2 -1
  33. data/ext/panko_serializer/attributes_writer/hash.c +3 -2
  34. data/ext/panko_serializer/attributes_writer/hash.h +2 -4
  35. data/ext/panko_serializer/attributes_writer/plain.c +2 -1
  36. data/ext/panko_serializer/attributes_writer/plain.h +2 -4
  37. data/ext/panko_serializer/attributes_writer/type_cast/type_cast.c +9 -9
  38. data/ext/panko_serializer/attributes_writer/type_cast/type_cast.h +2 -3
  39. data/ext/panko_serializer/common.h +0 -2
  40. data/ext/panko_serializer/panko_serializer.c +6 -8
  41. data/ext/panko_serializer/serialization_descriptor/association.c +1 -0
  42. data/ext/panko_serializer/serialization_descriptor/association.h +1 -1
  43. data/ext/panko_serializer/serialization_descriptor/attribute.c +1 -0
  44. data/ext/panko_serializer/serialization_descriptor/attribute.h +2 -2
  45. data/ext/panko_serializer/serialization_descriptor/serialization_descriptor.c +1 -1
  46. data/ext/panko_serializer/serialization_descriptor/serialization_descriptor.h +1 -1
  47. data/lib/panko/attribute.rb +5 -5
  48. data/lib/panko/object_writer.rb +5 -1
  49. data/lib/panko/response.rb +3 -3
  50. data/lib/panko/serialization_descriptor.rb +2 -2
  51. data/lib/panko/serializer.rb +8 -2
  52. data/lib/panko/serializer_resolver.rb +7 -4
  53. data/lib/panko/version.rb +1 -1
  54. data/panko_serializer.gemspec +8 -8
  55. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4d6afa062eeef46ccbd192d068e9d407003acfd98dd60b3e269caff356bb756
4
- data.tar.gz: 5049cbdef5d0e33e3731fe4a1469a047726c9b25be853d79f692b6eabe0888b5
3
+ metadata.gz: c07649ad9566fb8f9ef1088a20bff7b93f76b5d6295d0505b81bca45ed47788c
4
+ data.tar.gz: a9d3736b9ef189d9087f036bcf9c4977ae950ffbb1e3dfb1386ec138fdcef101
5
5
  SHA512:
6
- metadata.gz: ef58e0cd54374934883ac2dd17146e00ddcdc7f2858664cfb57f78e113990ebe2a766e6766c71bd217db842e96024ff51695ef34a16506ab9d50e6f01462b271
7
- data.tar.gz: d4bb8d589442812bd12a0e2d4c9d477ab3f5280c1eb9f80594eb93ca5e4153bbbbe0aa2ed517f851b247722d1d8c6240d7cb68dd625f067421a149b04988401b
6
+ metadata.gz: 609057962ee4975e8e392da3d762421e819f1bbac4d2511c156384732d9359922edd386d833353d112edea334f66c6a4f44f0dc593b16a8b1e62b2c64196f4df
7
+ data.tar.gz: 18d84743b9f94f59db2bffd7716ecd6e796da1d3c135b401d5c8f0ae258f3c74276706794703d3841663add5cec70fee97ccbf54561688ee9247cdd11bc6d115
@@ -19,7 +19,7 @@ jobs:
19
19
  - name: Use Node.js ${{ matrix.node-version }}
20
20
  uses: actions/setup-node@v1
21
21
  with:
22
- node-version: '12.x'
22
+ node-version: '16.x'
23
23
 
24
24
  - name: Install Dependencies
25
25
  working-directory: ${{ env.working_directory }}
@@ -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"
@@ -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: ['2.6', '2.7', '3.0']
13
- rails: ['6.0.0', '6.1.0']
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
- - uses: actions/checkout@v2
17
- - name: Set up Ruby ${{ matrix.ruby }}
18
- uses: actions/setup-ruby@v1
19
- with:
20
- ruby-version: ${{ matrix.ruby }}
21
-
22
- - name: Install deps
23
- run: |
24
- sudo apt update -y
25
- sudo apt install -y libsqlite3-dev
26
-
27
- - name: Gems Cache
28
- id: gem-cache
29
- uses: actions/cache@v1
30
- with:
31
- path: vendor/bundle
32
- key: ${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.rails }}-gem
33
- restore-keys: |
34
- ${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.rails }}-gem
35
-
36
- - name: Install gems
37
- env:
38
- RAILS_VERSION: ${{ matrix.rails }}
39
- run: |
40
- gem install bundler
41
- bundle config set path 'vendor/bundle'
42
- bundle check || bundle install --jobs 4 --retry 3
43
-
44
- - name: Compile & test
45
- env:
46
- RAILS_VERSION: ${{ matrix.rails }}
47
- run: |
48
- bundle exec rake
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
@@ -0,0 +1,4 @@
1
+ ignore:
2
+ - "ext/**/*"
3
+ - "spec/**/*":
4
+ - Lint/ConstantDefinitionInBlock
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( File.dirname(__FILE__) + "/panko_serializer.gemspec" )
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
- begin
36
- stdout.each do |line|
37
- print_and_flush '.'
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
- begin
58
- row = JSON.parse(line)
59
- row.values
60
- rescue JSON::ParserError
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
@@ -1,5 +1,5 @@
1
-
2
1
  # frozen_string_literal: true
2
+
3
3
  require_relative "./benchmarking_support"
4
4
  require_relative "./app"
5
5
  require_relative "./setup"
data/benchmarks/app.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require "bundler/setup"
3
2
 
3
+ require "bundler/setup"
4
4
 
5
5
  require "active_model"
6
6
  require "active_record"
@@ -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
- { all: posts, small: posts_50 }
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 block_given?
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
 
@@ -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('/dev/null'))
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
-
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative "./benchmarking_support"
3
4
  require_relative "./app"
4
5
 
@@ -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, :author, :author_id
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 = 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
- { all: posts, small: posts.first(50) }
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 *generate_attributes(5)
13
+ attributes(*generate_attributes(5))
13
14
  end
14
15
 
15
16
  class LeafBSerializer < Panko::Serializer
16
- attributes *generate_attributes(6)
17
+ attributes(*generate_attributes(6))
17
18
  end
18
19
 
19
20
  class ChildrenSerializer < Panko::Serializer
20
- attributes *generate_attributes(28)
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 *generate_attributes(46)
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
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative "./benchmarking_support"
3
4
  require_relative "./app"
4
5
 
@@ -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 = 'posts'
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
@@ -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".freeze] = "application/json".freeze
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, 'not found #{method.to_s.upcase} #{path}'
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 = 'posts'
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: { a: 1, b: 2, c: 3 }
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
- date = DateTime.new(2017, 3, 4, 12, 45, 23)
32
- tz = ActiveSupport::TimeZone.new("UTC")
33
- from = date.in_time_zone(tz).iso8601
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