panko_serializer 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/benchmarks/sanity.rb +36 -2
- data/ext/panko_serializer/attribute.c +20 -0
- data/lib/panko/serializer_resolver.rb +0 -1
- data/lib/panko/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2b1c0dbc2c75d9b48d7b2057ef66f2150702e86db83110e552ba8b99dfb7662
|
4
|
+
data.tar.gz: b980005c2670d69ba9093fd9aa4bee57f2f106eeedbccbd8739b64004591f62b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d27d528c54db62acffb611c5eba616f6346e410a78c9fe52835ccb5a60c4253e890f58dbc4aa6316f496db45fd1da7b4b79b4751fbd3898588b91efe715fb83e
|
7
|
+
data.tar.gz: ddf22bfc9d998fea61482a9e6ec71c460848401b7c922352f1c37395e717944c7cad77537133f90751a6cc9581e507cbb06d927af484f03bded9966a74e549e3
|
data/benchmarks/sanity.rb
CHANGED
@@ -3,6 +3,40 @@ require_relative "./benchmarking_support"
|
|
3
3
|
require_relative "./app"
|
4
4
|
require_relative "./setup"
|
5
5
|
|
6
|
+
class PostWithAliasModel < ActiveRecord::Base
|
7
|
+
self.table_name = 'posts'
|
8
|
+
|
9
|
+
alias_attribute :new_id, :id
|
10
|
+
alias_attribute :new_body, :body
|
11
|
+
alias_attribute :new_title, :title
|
12
|
+
alias_attribute :new_author_id, :author_id
|
13
|
+
alias_attribute :new_created_at, :created_at
|
14
|
+
end
|
15
|
+
|
16
|
+
class PostWithAliasFastSerializer < Panko::Serializer
|
17
|
+
attributes :new_id, :new_body, :new_title, :new_author_id, :new_created_at
|
18
|
+
end
|
19
|
+
|
20
|
+
def benchmark_aliased(prefix, serializer, options = {})
|
21
|
+
posts = PostWithAliasModel.all.to_a
|
22
|
+
posts_50 = posts.first(50).to_a
|
23
|
+
data = { all: posts, small: posts_50 }
|
24
|
+
|
25
|
+
merged_options = options.merge(each_serializer: serializer)
|
26
|
+
|
27
|
+
Benchmark.run("Panko_#{prefix}_PostWithAliasModels_#{posts.count}") do
|
28
|
+
Panko::ArraySerializer.new(posts, merged_options).to_json
|
29
|
+
end
|
30
|
+
|
31
|
+
posts = PostWithAliasModel.all.to_a
|
32
|
+
posts_50 = posts.first(50).to_a
|
33
|
+
data = { all: posts, small: posts_50 }
|
34
|
+
|
35
|
+
Benchmark.run("Panko_#{prefix}_Posts_50") do
|
36
|
+
Panko::ArraySerializer.new(posts_50, merged_options).to_json
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
6
40
|
class AuthorFastSerializer < Panko::Serializer
|
7
41
|
attributes :id, :name
|
8
42
|
end
|
@@ -55,7 +89,7 @@ end
|
|
55
89
|
|
56
90
|
|
57
91
|
|
58
|
-
|
59
|
-
benchmark 'SimpleWithMethodCall', PostFastWithMethodCallSerializer
|
92
|
+
benchmark "SimpleWithMethodCall", PostFastWithMethodCallSerializer
|
60
93
|
benchmark "HasOne", PostWithHasOneFastSerializer
|
61
94
|
benchmark "Simple", PostFastSerializer
|
95
|
+
benchmark_aliased "Simple (aliased)", PostWithAliasFastSerializer
|
@@ -1,5 +1,6 @@
|
|
1
1
|
#include "attribute.h"
|
2
2
|
|
3
|
+
ID attribute_aliases_id = 0;
|
3
4
|
VALUE cAttribute;
|
4
5
|
|
5
6
|
static void attribute_free(void* ptr) {
|
@@ -50,6 +51,23 @@ void attribute_try_invalidate(Attribute attribute, VALUE new_record_class) {
|
|
50
51
|
if (rb_equal(attribute->record_class, new_record_class) == Qfalse) {
|
51
52
|
attribute->type = Qnil;
|
52
53
|
attribute->record_class = new_record_class;
|
54
|
+
|
55
|
+
// Once the record class is changed for this attribute, check if
|
56
|
+
// we attribute_aliases (from ActivRecord), if so fill in
|
57
|
+
// performance wise - this code should be called once (unless the serialzier
|
58
|
+
// is polymorphic)
|
59
|
+
volatile VALUE ar_aliases_hash =
|
60
|
+
rb_funcall(new_record_class, attribute_aliases_id, 0);
|
61
|
+
|
62
|
+
if (!panko_is_empty_hash(ar_aliases_hash)) {
|
63
|
+
volatile VALUE aliasedValue =
|
64
|
+
rb_hash_aref(ar_aliases_hash, attribute->name_str);
|
65
|
+
if (aliasedValue != Qnil) {
|
66
|
+
attribute->alias_name = attribute->name_str;
|
67
|
+
attribute->name_str = aliasedValue;
|
68
|
+
attribute->name_id = rb_intern_str(attribute->name_str);
|
69
|
+
}
|
70
|
+
}
|
53
71
|
}
|
54
72
|
}
|
55
73
|
|
@@ -64,6 +82,8 @@ VALUE attribute_alias_name_ref(VALUE self) {
|
|
64
82
|
}
|
65
83
|
|
66
84
|
void panko_init_attribute(VALUE mPanko) {
|
85
|
+
attribute_aliases_id = rb_intern("attribute_aliases");
|
86
|
+
|
67
87
|
cAttribute = rb_define_class_under(mPanko, "Attribute", rb_cObject);
|
68
88
|
|
69
89
|
rb_define_module_function(cAttribute, "new", attribute_new, -1);
|
data/lib/panko/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: panko_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yosi Attias
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
version: '0'
|
166
166
|
requirements: []
|
167
167
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.7.
|
168
|
+
rubygems_version: 2.7.4
|
169
169
|
signing_key:
|
170
170
|
specification_version: 4
|
171
171
|
summary: Fast serialization for ActiveModel
|