panko_serializer 0.8.1 → 0.8.3
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/dependabot.yml +6 -0
- data/.github/workflows/docs.yml +6 -6
- data/.github/workflows/lint.yml +9 -19
- data/.github/workflows/ruby.yml +14 -10
- data/.gitignore +2 -0
- data/.rubocop.yml +29 -21
- data/Appraisals +29 -0
- data/Gemfile +12 -14
- data/README.md +6 -7
- data/Rakefile +3 -1
- data/benchmarks/allocs.rb +2 -2
- data/benchmarks/benchmarking_support.rb +2 -1
- data/benchmarks/bm_ams_0_10.rb +3 -7
- data/benchmarks/bm_panko_json.rb +2 -6
- data/benchmarks/bm_panko_object.rb +2 -6
- data/benchmarks/bm_plain_object.rb +1 -4
- data/benchmarks/bm_serialization_descriptor.rb +1 -1
- data/benchmarks/bm_to_object.rb +2 -6
- data/benchmarks/profile.rb +2 -2
- data/benchmarks/sanity.rb +2 -6
- data/benchmarks/setup.rb +4 -3
- data/benchmarks/type_casts/bm_active_record.rb +10 -39
- data/benchmarks/type_casts/bm_panko.rb +3 -6
- data/benchmarks/type_casts/support.rb +0 -1
- data/docs/docs/associations.md +20 -7
- data/docs/docs/attributes.md +29 -23
- data/docs/docs/design-choices.md +28 -27
- data/docs/docs/getting-started.md +9 -3
- data/docs/docs/introduction.md +5 -5
- data/docs/docs/performance.md +0 -1
- data/docs/docs/response-bag.md +8 -1
- data/docs/docusaurus.config.js +86 -0
- data/docs/package-lock.json +12607 -18674
- data/docs/package.json +14 -7
- data/docs/src/css/customTheme.css +9 -0
- data/docs/static/CNAME +1 -0
- data/ext/panko_serializer/attributes_writer/active_record.c +103 -72
- data/ext/panko_serializer/attributes_writer/active_record.h +2 -0
- data/ext/panko_serializer/attributes_writer/type_cast/type_cast.c +17 -0
- data/gemfiles/7.0.0.gemfile +39 -0
- data/gemfiles/7.0.0.gemfile.lock +176 -0
- data/gemfiles/7.1.0.gemfile +39 -0
- data/gemfiles/7.1.0.gemfile.lock +198 -0
- data/gemfiles/7.2.0.gemfile +39 -0
- data/gemfiles/7.2.0.gemfile.lock +198 -0
- data/gemfiles/8.0.0.gemfile +39 -0
- data/gemfiles/8.0.0.gemfile.lock +219 -0
- data/lib/panko/serializer.rb +1 -1
- data/lib/panko/version.rb +1 -1
- data/panko_serializer.gemspec +2 -1
- metadata +31 -10
- data/.standard.yml +0 -4
- data/docs/.DS_Store +0 -0
- data/docs/README.md +0 -198
- data/docs/core/Footer.js +0 -80
- data/docs/i18n/en.json +0 -50
- data/docs/siteConfig.js +0 -80
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e04b05a5a9a72ce68ad0768dd84b403e4adb6cefa8226f89c30a09d480993481
|
4
|
+
data.tar.gz: 1d7ff5f7b035a497e4b7d48e9749bfc13c3861cfb067b53b167b54c2ce5c8822
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bcb10f0e30eb48277dcdc9eea463dd475e892ed6eca37818d0d21eb9978cabeb1d0c7b1b8989ff69c1dc5c9b958fe8d0d073f0861d4b7207054e33677d615e7
|
7
|
+
data.tar.gz: 98846622471bed88140fe737f12144e9221e8a439c181c45d3e4ae1cd95aef265e640dd5bb4fda1d6beb8f4fc1f6eecc016620d31b9ec2a51fec6cc214683830
|
data/.github/workflows/docs.yml
CHANGED
@@ -5,7 +5,7 @@ name: Docs Publishing
|
|
5
5
|
|
6
6
|
on:
|
7
7
|
push:
|
8
|
-
branches: [ master ]
|
8
|
+
branches: [ master, docup ]
|
9
9
|
|
10
10
|
jobs:
|
11
11
|
build:
|
@@ -15,18 +15,18 @@ jobs:
|
|
15
15
|
working_directory: 'docs/'
|
16
16
|
|
17
17
|
steps:
|
18
|
-
- uses: actions/checkout@
|
18
|
+
- uses: actions/checkout@v4
|
19
19
|
- name: Use Node.js ${{ matrix.node-version }}
|
20
|
-
uses: actions/setup-node@
|
20
|
+
uses: actions/setup-node@v4
|
21
21
|
with:
|
22
|
-
node-version: '
|
22
|
+
node-version: '20.x'
|
23
23
|
|
24
24
|
- name: Install Dependencies
|
25
25
|
working-directory: ${{ env.working_directory }}
|
26
26
|
run: npm install
|
27
27
|
|
28
28
|
- name: Install SSH Client 🔑
|
29
|
-
uses: webfactory/ssh-agent@v0.
|
29
|
+
uses: webfactory/ssh-agent@v0.6.0
|
30
30
|
with:
|
31
31
|
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
|
32
32
|
|
@@ -35,5 +35,5 @@ jobs:
|
|
35
35
|
run: |
|
36
36
|
git config --global user.email "action@github.com"
|
37
37
|
git config --global user.name "GitHub Action"
|
38
|
-
GIT_USER=yosiat CURRENT_BRANCH=master USE_SSH=true npm run
|
38
|
+
GIT_USER=yosiat CURRENT_BRANCH=master USE_SSH=true npm run deploy
|
39
39
|
|
data/.github/workflows/lint.yml
CHANGED
@@ -7,33 +7,23 @@ jobs:
|
|
7
7
|
runs-on: ubuntu-latest
|
8
8
|
|
9
9
|
steps:
|
10
|
-
- uses: actions/checkout@
|
11
|
-
- name: Set up Ruby
|
12
|
-
uses: ruby/setup-ruby@v1
|
13
|
-
with:
|
14
|
-
ruby-version: 3.1.0
|
10
|
+
- uses: actions/checkout@v4
|
15
11
|
|
16
12
|
- name: Install deps
|
17
13
|
run: |
|
18
14
|
sudo apt update -y
|
19
15
|
sudo apt install -y libsqlite3-dev
|
20
16
|
|
21
|
-
- name:
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
bundle
|
28
|
-
|
29
|
-
- name: Lint ruby
|
30
|
-
env:
|
31
|
-
RAILS_VERSION: "7.0"
|
32
|
-
run: |
|
33
|
-
bundle exec rake standard
|
17
|
+
- name: Lint Ruby code
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: 3
|
21
|
+
bundler-cache: true
|
22
|
+
- run: |
|
23
|
+
bundle exec rake rubocop
|
34
24
|
|
35
25
|
- name: Lint C
|
36
|
-
uses: jidicula/clang-format-action@v4.
|
26
|
+
uses: jidicula/clang-format-action@v4.13.0
|
37
27
|
with:
|
38
28
|
clang-format-version: "16"
|
39
29
|
check-path: "ext/panko_serializer"
|
data/.github/workflows/ruby.yml
CHANGED
@@ -8,24 +8,28 @@ jobs:
|
|
8
8
|
strategy:
|
9
9
|
fail-fast: false
|
10
10
|
matrix:
|
11
|
-
ruby: ["3.
|
12
|
-
rails: ["
|
11
|
+
ruby: ["3.1", "3.2", "3.3"]
|
12
|
+
rails: ["7.0.0", "7.1.0", "7.2.0", "8.0.0"]
|
13
|
+
exclude:
|
14
|
+
- ruby: 3.1
|
15
|
+
rails: 8.0.0
|
13
16
|
|
14
17
|
steps:
|
15
|
-
-
|
18
|
+
- name: Install deps
|
19
|
+
run: |
|
20
|
+
sudo apt update -y
|
21
|
+
sudo apt install -y libsqlite3-dev
|
22
|
+
|
23
|
+
- uses: actions/checkout@v4
|
16
24
|
- name: Set up Ruby ${{ matrix.ruby }}
|
17
25
|
uses: ruby/setup-ruby@v1
|
18
26
|
with:
|
19
27
|
ruby-version: ${{ matrix.ruby }}
|
20
28
|
|
21
|
-
- name: Install deps
|
22
|
-
run: |
|
23
|
-
sudo apt update -y
|
24
|
-
sudo apt install -y libsqlite3-dev
|
25
29
|
|
26
30
|
- name: Gems Cache
|
27
31
|
id: gem-cache
|
28
|
-
uses: actions/cache@
|
32
|
+
uses: actions/cache@v4
|
29
33
|
with:
|
30
34
|
path: vendor/bundle
|
31
35
|
key: ${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
@@ -34,7 +38,7 @@ jobs:
|
|
34
38
|
|
35
39
|
- name: Install gems
|
36
40
|
env:
|
37
|
-
|
41
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile
|
38
42
|
run: |
|
39
43
|
gem install bundler
|
40
44
|
bundle config set path 'vendor/bundle'
|
@@ -42,6 +46,6 @@ jobs:
|
|
42
46
|
|
43
47
|
- name: Compile & test
|
44
48
|
env:
|
45
|
-
|
49
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile
|
46
50
|
run: |
|
47
51
|
bundle exec rake
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,29 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# We want Exclude directives from different
|
2
|
+
# config files to get merged, not overwritten
|
3
|
+
inherit_mode:
|
4
|
+
merge:
|
5
|
+
- Exclude
|
6
|
+
|
7
|
+
require:
|
8
|
+
- standard
|
9
|
+
- rubocop-performance
|
10
|
+
- standard-performance
|
11
|
+
- rubocop-rspec
|
12
|
+
|
13
|
+
inherit_gem:
|
14
|
+
standard: config/base.yml
|
15
|
+
standard-performance: config/base.yml
|
5
16
|
|
6
|
-
|
7
|
-
|
17
|
+
AllCops:
|
18
|
+
TargetRubyVersion: 3.1
|
19
|
+
SuggestExtensions: false
|
20
|
+
NewCops: disable
|
21
|
+
Exclude:
|
22
|
+
- ext/**/*
|
23
|
+
- gemfiles/**/*
|
8
24
|
|
9
|
-
Style/StringLiterals:
|
10
|
-
EnforcedStyle: double_quotes
|
11
25
|
|
12
26
|
Style/FrozenStringLiteralComment:
|
13
27
|
Enabled: true
|
14
28
|
EnforcedStyle: always
|
29
|
+
SafeAutoCorrect: true
|
15
30
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
Layout/TrailingWhitespace:
|
20
|
-
Enabled: true
|
31
|
+
# TODO: need to work on specs.
|
32
|
+
RSpec:
|
33
|
+
Enabled: false
|
21
34
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
Style/RedundantFreeze:
|
26
|
-
Enabled: true
|
27
|
-
|
28
|
-
Performance/UnfreezeString:
|
29
|
-
Enabled: true
|
35
|
+
Lint/ConstantDefinitionInBlock:
|
36
|
+
Exclude:
|
37
|
+
- spec/**/*
|
data/Appraisals
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
appraise "7.0.0" do
|
4
|
+
gem "sqlite3", "~> 1.4"
|
5
|
+
gem "activesupport", "~> 7.0.0"
|
6
|
+
gem "activemodel", "~> 7.0.0"
|
7
|
+
gem "activerecord", "~> 7.0.0", group: :test
|
8
|
+
end
|
9
|
+
|
10
|
+
appraise "7.1.0" do
|
11
|
+
gem "sqlite3", "~> 1.4"
|
12
|
+
gem "activesupport", "~> 7.1.5"
|
13
|
+
gem "activemodel", "~> 7.1.5"
|
14
|
+
gem "activerecord", "~> 7.1.5", group: :test
|
15
|
+
end
|
16
|
+
|
17
|
+
appraise "7.2.0" do
|
18
|
+
gem "sqlite3", "~> 1.4"
|
19
|
+
gem "activesupport", "~> 7.2.0"
|
20
|
+
gem "activemodel", "~> 7.2.0"
|
21
|
+
gem "activerecord", "~> 7.2.0", group: :test
|
22
|
+
end
|
23
|
+
|
24
|
+
appraise "8.0.0" do
|
25
|
+
gem "sqlite3", ">= 2.1"
|
26
|
+
gem "activesupport", "~> 8.0.0"
|
27
|
+
gem "activemodel", "~> 8.0.0"
|
28
|
+
gem "activerecord", "~> 8.0.0", group: :test
|
29
|
+
end
|
data/Gemfile
CHANGED
@@ -4,24 +4,15 @@ source "https://rubygems.org"
|
|
4
4
|
|
5
5
|
gemspec
|
6
6
|
|
7
|
-
raw_rails_version = ENV.fetch("RAILS_VERSION", "6.1.0")
|
8
|
-
rails_version = "~> #{raw_rails_version}"
|
9
|
-
|
10
|
-
gem "activesupport", rails_version
|
11
|
-
gem "activemodel", rails_version
|
12
|
-
gem "activerecord", rails_version, group: :test
|
13
|
-
|
14
7
|
group :benchmarks do
|
15
|
-
gem "
|
16
|
-
gem "
|
17
|
-
|
18
|
-
gem "memory_profiler"
|
19
|
-
gem "ruby-prof", platforms: [:mri]
|
20
|
-
gem "ruby-prof-flamegraph", platforms: [:mri]
|
8
|
+
gem "vernier"
|
9
|
+
gem "stackprof"
|
10
|
+
gem "pg"
|
21
11
|
|
22
12
|
gem "benchmark-ips"
|
23
13
|
gem "active_model_serializers", "~> 0.10"
|
24
14
|
gem "terminal-table"
|
15
|
+
gem "memory_profiler"
|
25
16
|
end
|
26
17
|
|
27
18
|
group :test do
|
@@ -35,4 +26,11 @@ group :development do
|
|
35
26
|
gem "rake-compiler"
|
36
27
|
end
|
37
28
|
|
38
|
-
|
29
|
+
group :development, :test do
|
30
|
+
gem "rubocop"
|
31
|
+
|
32
|
+
gem "standard"
|
33
|
+
gem "standard-performance"
|
34
|
+
gem "rubocop-performance"
|
35
|
+
gem "rubocop-rspec"
|
36
|
+
end
|
data/README.md
CHANGED
@@ -2,25 +2,24 @@
|
|
2
2
|
|
3
3
|

|
4
4
|
|
5
|
-
Panko is library which is inspired by ActiveModelSerializers 0.9 for serializing ActiveRecord/Ruby objects to JSON strings, fast.
|
5
|
+
Panko is a library which is inspired by ActiveModelSerializers 0.9 for serializing ActiveRecord/Ruby objects to JSON strings, fast.
|
6
6
|
|
7
|
-
To achieve
|
7
|
+
To achieve its [performance](https://panko.dev/docs/performance/):
|
8
8
|
|
9
|
-
* Oj - Panko relies Oj since it's fast and
|
9
|
+
* Oj - Panko relies on Oj since it's fast and allows for incremental serialization using `Oj::StringWriter`
|
10
10
|
* Serialization Descriptor - Panko computes most of the metadata ahead of time, to save time later in serialization.
|
11
|
-
* Type casting — Panko does type casting by
|
11
|
+
* Type casting — Panko does type casting by itself, instead of relying on ActiveRecord.
|
12
12
|
|
13
|
-
To dig deeper about the performance choices, read [Design Choices](https://panko.dev/docs/design-choices
|
13
|
+
To dig deeper about the performance choices, read [Design Choices](https://panko.dev/docs/design-choices/).
|
14
14
|
|
15
15
|
|
16
16
|
Support
|
17
17
|
-------
|
18
18
|
|
19
19
|
- [Documentation](https://panko.dev/docs)
|
20
|
-
- [Getting Started](https://panko.dev/docs/getting-started
|
20
|
+
- [Getting Started](https://panko.dev/docs/getting-started/)
|
21
21
|
|
22
22
|
License
|
23
23
|
-------
|
24
24
|
|
25
25
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
26
|
-
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require "json"
|
|
6
6
|
require "terminal-table"
|
7
7
|
require "rake/extensiontask"
|
8
8
|
require "pty"
|
9
|
-
require "
|
9
|
+
require "rubocop/rake_task"
|
10
10
|
|
11
11
|
gem = Gem::Specification.load(File.dirname(__FILE__) + "/panko_serializer.gemspec")
|
12
12
|
|
@@ -24,6 +24,8 @@ Rake::Task[:compile].prerequisites << :clean
|
|
24
24
|
|
25
25
|
task default: :spec
|
26
26
|
|
27
|
+
RuboCop::RakeTask.new
|
28
|
+
|
27
29
|
def print_and_flush(str)
|
28
30
|
print str
|
29
31
|
$stdout.flush
|
data/benchmarks/allocs.rb
CHANGED
@@ -10,8 +10,8 @@ class PostFastSerializer < Panko::Serializer
|
|
10
10
|
attributes :id, :body, :title, :author_id
|
11
11
|
end
|
12
12
|
|
13
|
-
def count_allocs(&
|
14
|
-
memory_report = MemoryProfiler.report(&
|
13
|
+
def count_allocs(&)
|
14
|
+
memory_report = MemoryProfiler.report(&)
|
15
15
|
puts memory_report.pretty_print
|
16
16
|
end
|
17
17
|
|
@@ -9,7 +9,8 @@ module Benchmark
|
|
9
9
|
def data
|
10
10
|
posts = Post.all.includes(:author).to_a
|
11
11
|
posts_50 = posts.first(50).to_a
|
12
|
-
|
12
|
+
posts_single = posts.first(1).to_a
|
13
|
+
{all: posts, small: posts_50, single: posts_single}
|
13
14
|
end
|
14
15
|
|
15
16
|
def run(label = nil, time: 10, disable_gc: true, warmup: 3, &block)
|
data/benchmarks/bm_ams_0_10.rb
CHANGED
@@ -5,7 +5,7 @@ require_relative "app"
|
|
5
5
|
require_relative "setup"
|
6
6
|
|
7
7
|
# disable logging for benchmarks
|
8
|
-
ActiveModelSerializers.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(
|
8
|
+
ActiveModelSerializers.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(File::NULL))
|
9
9
|
|
10
10
|
class AmsAuthorFastSerializer < ActiveModel::Serializer
|
11
11
|
attributes :id, :name
|
@@ -24,17 +24,13 @@ end
|
|
24
24
|
def benchmark_ams(prefix, serializer, options = {})
|
25
25
|
merged_options = options.merge(each_serializer: serializer)
|
26
26
|
|
27
|
-
|
28
|
-
posts = data[:all]
|
29
|
-
posts_50 = data[:small]
|
27
|
+
posts = Benchmark.data[:all]
|
30
28
|
|
31
29
|
Benchmark.run("AMS_#{prefix}_Posts_#{posts.count}") do
|
32
30
|
ActiveModelSerializers::SerializableResource.new(posts, merged_options).to_json
|
33
31
|
end
|
34
32
|
|
35
|
-
|
36
|
-
posts = data[:all]
|
37
|
-
posts_50 = data[:small]
|
33
|
+
posts_50 = Benchmark.data[:small]
|
38
34
|
|
39
35
|
Benchmark.run("AMS_#{prefix}_Posts_50") do
|
40
36
|
ActiveModelSerializers::SerializableResource.new(posts_50, merged_options).to_json
|
data/benchmarks/bm_panko_json.rb
CHANGED
@@ -37,9 +37,7 @@ class AuthorWithHasManyFastSerializer < Panko::Serializer
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def benchmark(prefix, serializer, options = {})
|
40
|
-
|
41
|
-
posts = data[:all]
|
42
|
-
posts_50 = data[:small]
|
40
|
+
posts = Benchmark.data[:all]
|
43
41
|
|
44
42
|
merged_options = options.merge(each_serializer: serializer)
|
45
43
|
|
@@ -47,9 +45,7 @@ def benchmark(prefix, serializer, options = {})
|
|
47
45
|
Panko::ArraySerializer.new(posts, merged_options).to_json
|
48
46
|
end
|
49
47
|
|
50
|
-
|
51
|
-
posts = data[:all]
|
52
|
-
posts_50 = data[:small]
|
48
|
+
posts_50 = Benchmark.data[:small]
|
53
49
|
|
54
50
|
Benchmark.run("Panko_ActiveRecord_#{prefix}_Posts_50") do
|
55
51
|
Panko::ArraySerializer.new(posts_50, merged_options).to_json
|
@@ -25,9 +25,7 @@ class AuthorWithHasManyFastSerializer < Panko::Serializer
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def benchmark(prefix, serializer, options = {})
|
28
|
-
|
29
|
-
posts = data[:all]
|
30
|
-
posts_50 = data[:small]
|
28
|
+
posts = Benchmark.data[:all]
|
31
29
|
|
32
30
|
merged_options = options.merge(each_serializer: serializer)
|
33
31
|
|
@@ -35,9 +33,7 @@ def benchmark(prefix, serializer, options = {})
|
|
35
33
|
Panko::ArraySerializer.new(posts, merged_options).to_a
|
36
34
|
end
|
37
35
|
|
38
|
-
|
39
|
-
posts = data[:all]
|
40
|
-
posts_50 = data[:small]
|
36
|
+
posts_50 = Benchmark.data[:small]
|
41
37
|
|
42
38
|
Benchmark.run("Panko_ActiveRecord_#{prefix}_Posts_50") do
|
43
39
|
Panko::ArraySerializer.new(posts_50, merged_options).to_a
|
@@ -78,7 +78,6 @@ end
|
|
78
78
|
def benchmark(prefix, serializer, options = {})
|
79
79
|
data = benchmark_data
|
80
80
|
posts = data[:all]
|
81
|
-
posts_50 = data[:small]
|
82
81
|
|
83
82
|
merged_options = options.merge(each_serializer: serializer)
|
84
83
|
|
@@ -86,9 +85,7 @@ def benchmark(prefix, serializer, options = {})
|
|
86
85
|
Panko::ArraySerializer.new(posts, merged_options).to_json
|
87
86
|
end
|
88
87
|
|
89
|
-
|
90
|
-
posts = data[:all]
|
91
|
-
posts_50 = data[:small]
|
88
|
+
posts_50 = benchmark_data[:small]
|
92
89
|
|
93
90
|
Benchmark.run("Panko_Plain_#{prefix}_Posts_50") do
|
94
91
|
Panko::ArraySerializer.new(posts_50, merged_options).to_json
|
data/benchmarks/bm_to_object.rb
CHANGED
@@ -62,9 +62,7 @@ class AuthorWithHasManyFastSerializer < Panko::Serializer
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def benchmark(prefix, serializer, options = {})
|
65
|
-
|
66
|
-
posts = data[:all]
|
67
|
-
posts_50 = data[:small]
|
65
|
+
posts = Benchmark.data[:all]
|
68
66
|
|
69
67
|
merged_options = options.merge(each_serializer: serializer)
|
70
68
|
|
@@ -72,9 +70,7 @@ def benchmark(prefix, serializer, options = {})
|
|
72
70
|
Panko::ArraySerializer.new(posts, merged_options).to_a
|
73
71
|
end
|
74
72
|
|
75
|
-
|
76
|
-
posts = data[:all]
|
77
|
-
posts_50 = data[:small]
|
73
|
+
posts_50 = Benchmark.data[:small]
|
78
74
|
|
79
75
|
Benchmark.run("Panko_#{prefix}_Posts_50") do
|
80
76
|
Panko::ArraySerializer.new(posts_50, merged_options).to_a
|
data/benchmarks/profile.rb
CHANGED
data/benchmarks/sanity.rb
CHANGED
@@ -62,9 +62,7 @@ class AuthorWithHasManyFastSerializer < Panko::Serializer
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def benchmark(prefix, serializer, options = {})
|
65
|
-
|
66
|
-
posts = data[:all]
|
67
|
-
posts_50 = data[:small]
|
65
|
+
posts = Benchmark.data[:all]
|
68
66
|
|
69
67
|
merged_options = options.merge(each_serializer: serializer)
|
70
68
|
|
@@ -72,9 +70,7 @@ def benchmark(prefix, serializer, options = {})
|
|
72
70
|
Panko::ArraySerializer.new(posts, merged_options).to_json
|
73
71
|
end
|
74
72
|
|
75
|
-
|
76
|
-
posts = data[:all]
|
77
|
-
posts_50 = data[:small]
|
73
|
+
posts_50 = Benchmark.data[:small]
|
78
74
|
|
79
75
|
Benchmark.run("Panko_#{prefix}_Posts_50") do
|
80
76
|
Panko::ArraySerializer.new(posts_50, merged_options).to_json
|
data/benchmarks/setup.rb
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
##########################################
|
6
6
|
require "active_record"
|
7
7
|
require "sqlite3"
|
8
|
+
require "securerandom"
|
8
9
|
|
9
10
|
# Change the following to reflect your database settings
|
10
11
|
ActiveRecord::Base.establish_connection(
|
@@ -46,9 +47,9 @@ Author.destroy_all
|
|
46
47
|
Post.transaction do
|
47
48
|
ENV.fetch("ITEMS_COUNT", "2300").to_i.times do
|
48
49
|
Post.create(
|
49
|
-
body:
|
50
|
-
title:
|
51
|
-
author: Author.create(name:
|
50
|
+
body: SecureRandom.hex(30),
|
51
|
+
title: SecureRandom.hex(20),
|
52
|
+
author: Author.create(name: SecureRandom.alphanumeric),
|
52
53
|
data: {a: 1, b: 2, c: 3}
|
53
54
|
)
|
54
55
|
end
|
@@ -5,26 +5,14 @@ require_relative "support"
|
|
5
5
|
def ar_type_convert(type_klass, from, to)
|
6
6
|
converter = type_klass.new
|
7
7
|
|
8
|
-
|
9
|
-
assert type_klass.name, converter.type_cast_from_database(from), to
|
8
|
+
assert type_klass.name, converter.deserialize(from), to
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
Benchmark.run("#{type_klass.name}_NoTypeCast") do
|
16
|
-
converter.type_cast_from_database(to)
|
17
|
-
end
|
18
|
-
else
|
19
|
-
assert type_klass.name, converter.deserialize(from), to
|
20
|
-
|
21
|
-
Benchmark.run("#{type_klass.name}_TypeCast") do
|
22
|
-
converter.deserialize(from)
|
23
|
-
end
|
10
|
+
Benchmark.run("#{type_klass.name}_TypeCast") do
|
11
|
+
converter.deserialize(from)
|
12
|
+
end
|
24
13
|
|
25
|
-
|
26
|
-
|
27
|
-
end
|
14
|
+
Benchmark.run("#{type_klass.name}_NoTypeCast") do
|
15
|
+
converter.deserialize(to)
|
28
16
|
end
|
29
17
|
end
|
30
18
|
|
@@ -36,14 +24,8 @@ def utc_ar_time
|
|
36
24
|
type = ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateTime.new
|
37
25
|
converter = ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter.new(type)
|
38
26
|
|
39
|
-
|
40
|
-
|
41
|
-
converter.type_cast_from_database(from).iso8601
|
42
|
-
end
|
43
|
-
else
|
44
|
-
Benchmark.run("#{tz}_#{type.class.name}_TypeCast") do
|
45
|
-
converter.deserialize(from).iso8601
|
46
|
-
end
|
27
|
+
Benchmark.run("#{tz}_#{type.class.name}_TypeCast") do
|
28
|
+
converter.deserialize(from).iso8601
|
47
29
|
end
|
48
30
|
end
|
49
31
|
|
@@ -53,14 +35,8 @@ def db_ar_time
|
|
53
35
|
|
54
36
|
from = "2017-07-10 09:26:40.937392"
|
55
37
|
|
56
|
-
|
57
|
-
|
58
|
-
converter.type_cast_from_database(from).iso8601
|
59
|
-
end
|
60
|
-
else
|
61
|
-
Benchmark.run("ActiveRecord_Time_TypeCast_WithISO8601") do
|
62
|
-
converter.deserialize(from).iso8601
|
63
|
-
end
|
38
|
+
Benchmark.run("ActiveRecord_Time_TypeCast_WithISO8601") do
|
39
|
+
converter.deserialize(from).iso8601
|
64
40
|
end
|
65
41
|
end
|
66
42
|
|
@@ -71,11 +47,6 @@ ar_type_convert ActiveRecord::Type::Float, "1.23", 1.23
|
|
71
47
|
ar_type_convert ActiveRecord::Type::Boolean, "true", true
|
72
48
|
ar_type_convert ActiveRecord::Type::Boolean, "t", true
|
73
49
|
|
74
|
-
if ENV["RAILS_VERSION"].start_with? "4.2"
|
75
|
-
ar_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer, "1", 1
|
76
|
-
ar_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Float, "1.23", 1.23
|
77
|
-
ar_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Float, "Infinity", ::Float::INFINITY
|
78
|
-
end
|
79
50
|
if check_if_exists "ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json"
|
80
51
|
ar_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json, '{"a":1}', {a: 1}
|
81
52
|
end
|
@@ -52,15 +52,12 @@ panko_type_convert ActiveRecord::Type::Float, "1.23", 1.23
|
|
52
52
|
panko_type_convert ActiveRecord::Type::Boolean, "true", true
|
53
53
|
panko_type_convert ActiveRecord::Type::Boolean, "t", true
|
54
54
|
|
55
|
-
if ENV["RAILS_VERSION"].start_with? "4.2"
|
56
|
-
panko_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer, "1", 1
|
57
|
-
panko_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Float, "1.23", 1.23
|
58
|
-
panko_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Float, "Infinity", ::Float::INFINITY
|
59
|
-
end
|
60
|
-
|
61
55
|
if check_if_exists "ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json"
|
62
56
|
panko_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json, '{"a":1}', '{"a":1}'
|
63
57
|
end
|
58
|
+
if check_if_exists "ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb"
|
59
|
+
panko_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb, '{"a":1}', '{"a":1}'
|
60
|
+
end
|
64
61
|
if check_if_exists "ActiveRecord::Type::Json"
|
65
62
|
panko_type_convert ActiveRecord::Type::Json, '{"a":1}', '{"a":1}'
|
66
63
|
end
|