panko_serializer 0.7.7 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/lint.yml +40 -0
- data/.github/workflows/ruby.yml +35 -39
- data/.standard.yml +4 -0
- data/Gemfile +4 -3
- data/README.md +1 -1
- data/Rakefile +32 -33
- 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 +4 -3
- 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 +8 -3
- data/docs/docs/introduction.md +1 -1
- data/docs/docs/performance.md +6 -6
- data/docs/package-lock.json +399 -330
- 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 +4 -6
- 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 +10 -10
- data/ext/panko_serializer/attributes_writer/type_cast/type_cast.h +4 -4
- data/ext/panko_serializer/common.h +0 -2
- data/ext/panko_serializer/panko_serializer.c +8 -9
- data/ext/panko_serializer/serialization_descriptor/association.c +3 -1
- data/ext/panko_serializer/serialization_descriptor/association.h +1 -1
- data/ext/panko_serializer/serialization_descriptor/attribute.c +3 -1
- data/ext/panko_serializer/serialization_descriptor/attribute.h +2 -2
- 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 +3 -3
- data/lib/panko/serializer_resolver.rb +6 -4
- data/lib/panko/version.rb +1 -1
- data/panko_serializer.gemspec +8 -8
- metadata +5 -3
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
|
@@ -1,36 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require_relative "./support"
|
3
4
|
|
4
5
|
def panko_type_convert(type_klass, from, to)
|
5
6
|
converter = type_klass.new
|
6
|
-
assert
|
7
|
+
assert type_klass.name.to_s, Panko._type_cast(converter, from), to
|
7
8
|
|
8
9
|
Benchmark.run("#{type_klass.name}_TypeCast") do
|
9
|
-
Panko
|
10
|
+
Panko._type_cast(converter, from)
|
10
11
|
end
|
11
12
|
|
12
13
|
Benchmark.run("#{type_klass.name}_NoTypeCast") do
|
13
|
-
Panko
|
14
|
+
Panko._type_cast(converter, to)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
18
|
def utc_panko_time
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
date = DateTime.new(2017, 3, 4, 12, 45, 23)
|
20
|
+
tz = ActiveSupport::TimeZone.new("UTC")
|
21
|
+
from = date.in_time_zone(tz).iso8601
|
22
22
|
|
23
23
|
type = ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateTime.new
|
24
24
|
converter = ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter.new(type)
|
25
25
|
|
26
|
-
to = Panko
|
26
|
+
to = Panko._type_cast(converter, from)
|
27
27
|
|
28
28
|
Benchmark.run("#{tz}_#{type.class.name}_TypeCast") do
|
29
|
-
Panko
|
29
|
+
Panko._type_cast(converter, from)
|
30
30
|
end
|
31
31
|
|
32
32
|
Benchmark.run("#{tz}_#{type.class.name}_NoTypeCast") do
|
33
|
-
Panko
|
33
|
+
Panko._type_cast(converter, to)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -41,7 +41,7 @@ def db_panko_time
|
|
41
41
|
from = "2017-07-10 09:26:40.937392"
|
42
42
|
|
43
43
|
Benchmark.run("Panko_Time_TypeCast") do
|
44
|
-
|
44
|
+
Panko._type_cast(converter, from)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "active_record"
|
3
4
|
require "active_record/connection_adapters/postgresql_adapter"
|
4
5
|
require "active_model"
|
@@ -6,18 +7,22 @@ require "active_support/all"
|
|
6
7
|
require "pg"
|
7
8
|
require "oj"
|
8
9
|
|
9
|
-
|
10
10
|
require_relative "../benchmarking_support"
|
11
|
-
require_relative "../../lib/
|
11
|
+
require_relative "../../lib/panko_serializer"
|
12
12
|
|
13
13
|
def assert(type_name, from, to)
|
14
14
|
raise "#{type_name} - #{from.class} is not equals to #{to.class}" unless from.to_json == to.to_json
|
15
15
|
end
|
16
16
|
|
17
17
|
def check_if_exists(module_name)
|
18
|
-
mod =
|
18
|
+
mod = begin
|
19
|
+
module_name.constantize
|
20
|
+
rescue
|
21
|
+
nil
|
22
|
+
end
|
19
23
|
return true if mod
|
20
24
|
return false unless mod
|
21
25
|
end
|
22
26
|
|
23
27
|
Time.zone = "UTC"
|
28
|
+
ActiveSupport::Deprecation.behavior = :stderr
|
data/docs/docs/introduction.md
CHANGED
@@ -8,6 +8,6 @@ Panko is library which is inspired by ActiveModelSerializers 0.9 for serializing
|
|
8
8
|
|
9
9
|
To achieve it's [performance](https://panko.dev/docs/performance.html):
|
10
10
|
|
11
|
-
* Oj - Panko relies Oj since it's fast and allow to
|
11
|
+
* Oj - Panko relies Oj since it's fast and allow to serialize incrementally using `Oj::StringWriter`
|
12
12
|
* Serialization Descriptor - Panko computes most of the metadata ahead of time, to save time later in serialization.
|
13
13
|
* Type casting — Panko does type casting by it's self, instead of relying ActiveRecord.
|
data/docs/docs/performance.md
CHANGED
@@ -8,15 +8,15 @@ The performance of Panko is measured using microbenchmarks and load testing.
|
|
8
8
|
|
9
9
|
## Microbenchmarks
|
10
10
|
|
11
|
-
The following microbenchmarks are run on MacBook Pro (16-inch, 2021, M1 Max), Ruby 3.
|
12
|
-
demonstrating the performance of ActiveModelSerializers 0.10.13 and Panko 0.
|
11
|
+
The following microbenchmarks are run on MacBook Pro (16-inch, 2021, M1 Max), Ruby 3.2.0 with Rails 7.0.5
|
12
|
+
demonstrating the performance of ActiveModelSerializers 0.10.13 and Panko 0.8.0
|
13
13
|
|
14
14
|
| Benchmark | AMS ip/s | Panko ip/s |
|
15
15
|
| ----------------- | -------- | ---------- |
|
16
|
-
| Simple_Posts_2300 | 11.
|
17
|
-
| Simple_Posts_50 |
|
18
|
-
| HasOne_Posts_2300 | 5.
|
19
|
-
| HasOne_Posts_50 |
|
16
|
+
| Simple_Posts_2300 | 11.72 | 523.05 |
|
17
|
+
| Simple_Posts_50 | 557.29 | 23,011.9 |
|
18
|
+
| HasOne_Posts_2300 | 5.91 | 233.44 |
|
19
|
+
| HasOne_Posts_50 | 285.8 | 10,362.79 |
|
20
20
|
|
21
21
|
## Real-world benchmark
|
22
22
|
|