mutils 0.2.35 → 1.1.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/CONTRIBUTING.md +3 -3
- data/.github/dependabot.yml +10 -0
- data/.gitignore +1 -0
- data/.huskyrc +7 -0
- data/.rspec +0 -1
- data/.rubocop.yml +2 -7
- data/.rubocop_todo.yml +10 -2
- data/.travis.yml +26 -4
- data/CHANGELOG.md +86 -45
- data/Gemfile +6 -0
- data/Gemfile.lock +44 -71
- data/README.md +135 -47
- data/SECURITY.md +13 -0
- data/Version +1 -0
- data/commitlint.config.js +1 -0
- data/gemdeploy.sh +10 -0
- data/lib/mutils.rb +3 -3
- data/lib/mutils/lib/helper.rb +42 -0
- data/lib/mutils/lib/result_hash.rb +25 -0
- data/lib/mutils/serialization/base_serializer.rb +0 -8
- data/lib/mutils/serialization/methods/attributes.rb +52 -0
- data/lib/mutils/serialization/methods/main.rb +27 -0
- data/lib/mutils/serialization/methods/relations.rb +40 -0
- data/lib/mutils/serialization/results/attributes.rb +24 -0
- data/lib/mutils/serialization/results/main.rb +59 -0
- data/lib/mutils/serialization/results/relations.rb +23 -0
- data/lib/mutils/serialization/serialization_includes.rb +9 -7
- data/lib/mutils/serialization/serialization_methods.rb +7 -69
- data/lib/mutils/serialization/serialization_results.rb +6 -71
- data/lib/mutils/version.rb +1 -1
- data/mutils.gemspec +5 -8
- data/package-lock.json +7157 -0
- data/package.json +94 -0
- metadata +25 -71
- data/.github/workflows/gempush.yml +0 -28
- data/.mergify.yml +0 -8
- data/.ruby-version +0 -1
- data/BENCHMARK-SERIALIZER-JSON.md +0 -82
- data/Makefile +0 -8
- data/benchmark/benchmark-serializer-json.rb +0 -252
data/package.json
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mutils-dev",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "used to install husky and commit lint",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"repository": "git@github.com:Code-Vedas/mutils.git",
|
|
7
|
+
"author": "Nitesh Purohit <nitesh.purohit.it@gmail.com>",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"private": true,
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@commitlint/cli": "^9.1.1",
|
|
12
|
+
"@commitlint/config-angular": "^9.1.1",
|
|
13
|
+
"@semantic-release/changelog": "^5.0.1",
|
|
14
|
+
"@semantic-release/exec": "^5.0.0",
|
|
15
|
+
"@semantic-release/git": "^9.0.0",
|
|
16
|
+
"@semantic-release/github": "^7.0.7",
|
|
17
|
+
"husky": "^4.2.5",
|
|
18
|
+
"lint-staged": "^10.2.11",
|
|
19
|
+
"semantic-release": "^17.1.1"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"copyfiles": "cp -r CHANGELOG.md dist/CHANGELOG.md && cp -r dist/package.json src/package.json",
|
|
23
|
+
"semantic-release": "semantic-release"
|
|
24
|
+
},
|
|
25
|
+
"lint-staged": {
|
|
26
|
+
"*.{rb}": [
|
|
27
|
+
"bundle exec rubocop lib"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"husky": {
|
|
31
|
+
"hooks": {
|
|
32
|
+
"pre-commit": "lint-staged",
|
|
33
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"release": {
|
|
37
|
+
"branch": "master",
|
|
38
|
+
"ci": false,
|
|
39
|
+
"verifyConditions": [
|
|
40
|
+
"@semantic-release/changelog",
|
|
41
|
+
"@semantic-release/git",
|
|
42
|
+
"@semantic-release/github"
|
|
43
|
+
],
|
|
44
|
+
"analyzeCommits": [
|
|
45
|
+
"@semantic-release/commit-analyzer"
|
|
46
|
+
],
|
|
47
|
+
"generateNotes": {
|
|
48
|
+
"path": "@semantic-release/release-notes-generator",
|
|
49
|
+
"preset": "angular",
|
|
50
|
+
"parserOpts": {
|
|
51
|
+
"noteKeywords": [
|
|
52
|
+
"BREAKING CHANGE",
|
|
53
|
+
"BREAKING CHANGES",
|
|
54
|
+
"BREAKING"
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
"writerOpts": {
|
|
58
|
+
"commitsSort": [
|
|
59
|
+
"scope",
|
|
60
|
+
"subject"
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"prepare": [
|
|
65
|
+
{
|
|
66
|
+
"path": "@semantic-release/changelog",
|
|
67
|
+
"changelogFile": "CHANGELOG.md"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"path": "@semantic-release/exec",
|
|
71
|
+
"cmd": "echo \"v${nextRelease.version}\" > Version"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"path": "@semantic-release/exec",
|
|
75
|
+
"cmd": "echo \"Deploying Version: $(cat Version)\""
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"path": "@semantic-release/exec",
|
|
79
|
+
"cmd": "./gemdeploy.sh"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"path": "@semantic-release/git",
|
|
83
|
+
"assets": [
|
|
84
|
+
"CHANGELOG.md",
|
|
85
|
+
"Version"
|
|
86
|
+
],
|
|
87
|
+
"message": "build(release): v${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
88
|
+
}
|
|
89
|
+
],
|
|
90
|
+
"publish": [
|
|
91
|
+
"@semantic-release/github"
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
}
|
metadata
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mutils
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nitesh Purohit
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-08-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: dry-inflector
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '0'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: bundler
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -38,20 +38,6 @@ dependencies:
|
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '2.0'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: coveralls
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - ">="
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '0'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - ">="
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '0'
|
|
55
41
|
- !ruby/object:Gem::Dependency
|
|
56
42
|
name: rake
|
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -66,48 +52,6 @@ dependencies:
|
|
|
66
52
|
- - "~>"
|
|
67
53
|
- !ruby/object:Gem::Version
|
|
68
54
|
version: '13.0'
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: rspec-json_expectations
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - ">="
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: '0'
|
|
76
|
-
type: :development
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - ">="
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: '0'
|
|
83
|
-
- !ruby/object:Gem::Dependency
|
|
84
|
-
name: rspec-rails
|
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
|
86
|
-
requirements:
|
|
87
|
-
- - ">="
|
|
88
|
-
- !ruby/object:Gem::Version
|
|
89
|
-
version: '0'
|
|
90
|
-
type: :development
|
|
91
|
-
prerelease: false
|
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
-
requirements:
|
|
94
|
-
- - ">="
|
|
95
|
-
- !ruby/object:Gem::Version
|
|
96
|
-
version: '0'
|
|
97
|
-
- !ruby/object:Gem::Dependency
|
|
98
|
-
name: rspec-xml_helpers
|
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
|
100
|
-
requirements:
|
|
101
|
-
- - ">="
|
|
102
|
-
- !ruby/object:Gem::Version
|
|
103
|
-
version: '0'
|
|
104
|
-
type: :development
|
|
105
|
-
prerelease: false
|
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
-
requirements:
|
|
108
|
-
- - ">="
|
|
109
|
-
- !ruby/object:Gem::Version
|
|
110
|
-
version: '0'
|
|
111
55
|
description: mutils Utilities for rails app
|
|
112
56
|
email:
|
|
113
57
|
- nitesh.purohit.it@gmail.com
|
|
@@ -121,42 +65,52 @@ files:
|
|
|
121
65
|
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
|
122
66
|
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
|
123
67
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
|
124
|
-
- ".github/
|
|
68
|
+
- ".github/dependabot.yml"
|
|
125
69
|
- ".gitignore"
|
|
126
|
-
- ".
|
|
70
|
+
- ".huskyrc"
|
|
127
71
|
- ".rspec"
|
|
128
72
|
- ".rubocop.yml"
|
|
129
73
|
- ".rubocop_todo.yml"
|
|
130
|
-
- ".ruby-version"
|
|
131
74
|
- ".travis.yml"
|
|
132
|
-
- BENCHMARK-SERIALIZER-JSON.md
|
|
133
75
|
- CHANGELOG.md
|
|
134
76
|
- CODE_OF_CONDUCT.md
|
|
135
77
|
- Gemfile
|
|
136
78
|
- Gemfile.lock
|
|
137
79
|
- LICENSE.txt
|
|
138
|
-
- Makefile
|
|
139
80
|
- README.md
|
|
140
81
|
- Rakefile
|
|
141
|
-
-
|
|
82
|
+
- SECURITY.md
|
|
83
|
+
- Version
|
|
142
84
|
- bin/console
|
|
143
85
|
- bin/setup
|
|
86
|
+
- commitlint.config.js
|
|
87
|
+
- gemdeploy.sh
|
|
144
88
|
- lib/generators/mutils/USAGE
|
|
145
89
|
- lib/generators/mutils/serializer_generator.rb
|
|
146
90
|
- lib/generators/mutils/templates/serializer.rb.tt
|
|
147
91
|
- lib/mutils.rb
|
|
92
|
+
- lib/mutils/lib/helper.rb
|
|
93
|
+
- lib/mutils/lib/result_hash.rb
|
|
148
94
|
- lib/mutils/serialization/base_serializer.rb
|
|
95
|
+
- lib/mutils/serialization/methods/attributes.rb
|
|
96
|
+
- lib/mutils/serialization/methods/main.rb
|
|
97
|
+
- lib/mutils/serialization/methods/relations.rb
|
|
98
|
+
- lib/mutils/serialization/results/attributes.rb
|
|
99
|
+
- lib/mutils/serialization/results/main.rb
|
|
100
|
+
- lib/mutils/serialization/results/relations.rb
|
|
149
101
|
- lib/mutils/serialization/serialization_includes.rb
|
|
150
102
|
- lib/mutils/serialization/serialization_methods.rb
|
|
151
103
|
- lib/mutils/serialization/serialization_results.rb
|
|
152
104
|
- lib/mutils/version.rb
|
|
153
105
|
- mutils.gemspec
|
|
154
|
-
|
|
106
|
+
- package-lock.json
|
|
107
|
+
- package.json
|
|
108
|
+
homepage: https://github.com/code-vedas/mutils
|
|
155
109
|
licenses:
|
|
156
110
|
- MIT
|
|
157
111
|
metadata:
|
|
158
|
-
bug_tracker_uri: https://github.com/
|
|
159
|
-
source_code_uri: https://github.com/
|
|
112
|
+
bug_tracker_uri: https://github.com/code-vedas/mutils/issues
|
|
113
|
+
source_code_uri: https://github.com/code-vedas/mutils/tree/v1.1.0
|
|
160
114
|
post_install_message:
|
|
161
115
|
rdoc_options: []
|
|
162
116
|
require_paths:
|
|
@@ -172,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
172
126
|
- !ruby/object:Gem::Version
|
|
173
127
|
version: 1.8.11
|
|
174
128
|
requirements: []
|
|
175
|
-
rubygems_version: 3.0.
|
|
129
|
+
rubygems_version: 3.0.8
|
|
176
130
|
signing_key:
|
|
177
131
|
specification_version: 4
|
|
178
132
|
summary: mutils Utilities for rails app
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
name: Ruby Gem
|
|
2
|
-
on:
|
|
3
|
-
release:
|
|
4
|
-
types: ["created"]
|
|
5
|
-
|
|
6
|
-
jobs:
|
|
7
|
-
build:
|
|
8
|
-
name: Build + Publish
|
|
9
|
-
runs-on: ubuntu-latest
|
|
10
|
-
|
|
11
|
-
steps:
|
|
12
|
-
- uses: actions/checkout@master
|
|
13
|
-
- name: Set up Ruby 2.6
|
|
14
|
-
uses: actions/setup-ruby@v1
|
|
15
|
-
with:
|
|
16
|
-
ruby-version: 2.6.x
|
|
17
|
-
|
|
18
|
-
- name: Publish to RubyGems
|
|
19
|
-
run: |
|
|
20
|
-
mkdir -p $HOME/.gem
|
|
21
|
-
touch $HOME/.gem/credentials
|
|
22
|
-
chmod 0600 $HOME/.gem/credentials
|
|
23
|
-
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
|
24
|
-
gem build *.gemspec
|
|
25
|
-
gem push *.gem
|
|
26
|
-
env:
|
|
27
|
-
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
|
|
28
|
-
|
data/.mergify.yml
DELETED
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.7.0
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
```
|
|
2
|
-
ruby benchmark/benchmark-serializer-json.rb
|
|
3
|
-
|
|
4
|
-
Rehearsal ------------------------------------------------
|
|
5
|
-
fast_jsonapi 0.469146 0.003692 0.472838 ( 0.482972)
|
|
6
|
-
==>mutils 0.343414 0.002338 0.345752 ( 0.350116)
|
|
7
|
-
as_json 0.349795 0.002601 0.352396 ( 0.355537)
|
|
8
|
-
grape_entity 2.123932 0.008031 2.131963 ( 2.142096)
|
|
9
|
-
blueprinter 0.729144 0.005669 0.734813 ( 0.737173)
|
|
10
|
-
roar 1.815007 0.015412 1.830419 ( 1.831867)
|
|
11
|
-
panko 0.324755 0.000970 0.325725 ( 0.325953)
|
|
12
|
-
--------------------------------------- total: 6.193906sec
|
|
13
|
-
|
|
14
|
-
user system total real
|
|
15
|
-
fast_jsonapi 0.326813 0.000479 0.327292 ( 0.328071)
|
|
16
|
-
==>mutils 0.228319 0.000145 0.228464 ( 0.228649)
|
|
17
|
-
as_json 0.252139 0.000242 0.252381 ( 0.252570)
|
|
18
|
-
grape_entity 1.820288 0.008052 1.828340 ( 1.837977)
|
|
19
|
-
blueprinter 0.656481 0.001270 0.657751 ( 0.659753)
|
|
20
|
-
roar 1.592949 0.008122 1.601071 ( 1.604941)
|
|
21
|
-
panko 0.260401 0.000433 0.260834 ( 0.261211)
|
|
22
|
-
|
|
23
|
-
Warming up --------------------------------------
|
|
24
|
-
fast_jsonapi 1.000 i/100ms
|
|
25
|
-
==>mutils 1.000 i/100ms
|
|
26
|
-
as_json 1.000 i/100ms
|
|
27
|
-
grape_entity 1.000 i/100ms
|
|
28
|
-
blueprinter 1.000 i/100ms
|
|
29
|
-
roar 1.000 i/100ms
|
|
30
|
-
panko 1.000 i/100ms
|
|
31
|
-
Calculating -------------------------------------
|
|
32
|
-
fast_jsonapi 2.215 (± 5.1%) i/s - 22.000 in 10.107915s
|
|
33
|
-
==>mutils 3.136 (± 3.0%) i/s - 32.000 in 10.281530s
|
|
34
|
-
as_json 3.455 (± 3.1%) i/s - 35.000 in 10.229037s
|
|
35
|
-
grape_entity 0.509 (± 7.2%) i/s - 6.000 in 11.844870s
|
|
36
|
-
blueprinter 1.337 (± 3.9%) i/s - 14.000 in 10.537541s
|
|
37
|
-
roar 0.613 (± 2.2%) i/s - 7.000 in 11.441661s
|
|
38
|
-
panko 3.527 (± 2.9%) i/s - 36.000 in 10.292679s
|
|
39
|
-
with 95.0% confidence
|
|
40
|
-
|
|
41
|
-
Comparison:
|
|
42
|
-
panko: 3.5 i/s
|
|
43
|
-
as_json: 3.5 i/s - same-ish: difference falls within error
|
|
44
|
-
==>mutils: 3.1 i/s - 1.13x (± 0.05) slower
|
|
45
|
-
fast_jsonapi: 2.2 i/s - 1.59x (± 0.09) slower
|
|
46
|
-
blueprinter: 1.3 i/s - 2.64x (± 0.13) slower
|
|
47
|
-
roar: 0.6 i/s - 5.76x (± 0.21) slower
|
|
48
|
-
grape_entity: 0.5 i/s - 6.93x (± 0.53) slower
|
|
49
|
-
with 95.0% confidence
|
|
50
|
-
|
|
51
|
-
Calculating -------------------------------------
|
|
52
|
-
fast_jsonapi 62.946M memsize ( 0.000 retained)
|
|
53
|
-
981.039k objects ( 0.000 retained)
|
|
54
|
-
50.000 strings ( 0.000 retained)
|
|
55
|
-
==>mutils 65.112M memsize ( 0.000 retained)
|
|
56
|
-
721.156k objects ( 0.000 retained)
|
|
57
|
-
0.000 strings ( 0.000 retained)
|
|
58
|
-
as_json 98.148M memsize ( 0.000 retained)
|
|
59
|
-
1.683M objects ( 0.000 retained)
|
|
60
|
-
8.000 strings ( 0.000 retained)
|
|
61
|
-
grape_entity 245.776M memsize ( 0.000 retained)
|
|
62
|
-
2.524M objects ( 0.000 retained)
|
|
63
|
-
4.000 strings ( 0.000 retained)
|
|
64
|
-
blueprinter 71.856M memsize ( 0.000 retained)
|
|
65
|
-
661.154k objects ( 0.000 retained)
|
|
66
|
-
0.000 strings ( 0.000 retained)
|
|
67
|
-
roar 221.022M memsize ( 0.000 retained)
|
|
68
|
-
1.823M objects ( 0.000 retained)
|
|
69
|
-
1.000 strings ( 0.000 retained)
|
|
70
|
-
panko 98.153M memsize ( 0.000 retained)
|
|
71
|
-
1.683M objects ( 0.000 retained)
|
|
72
|
-
13.000 strings ( 0.000 retained)
|
|
73
|
-
|
|
74
|
-
Comparison:
|
|
75
|
-
fast_jsonapi: 62945864 allocated
|
|
76
|
-
=>>mutils: 65111936 allocated - 1.03x more
|
|
77
|
-
blueprinter: 71856304 allocated - 1.14x more
|
|
78
|
-
as_json: 98148488 allocated - 1.56x more
|
|
79
|
-
panko: 98153072 allocated - 1.56x more
|
|
80
|
-
roar: 221022344 allocated - 3.51x more
|
|
81
|
-
grape_entity: 245775576 allocated - 3.90x morre
|
|
82
|
-
```
|
data/Makefile
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'bundler/inline'
|
|
4
|
-
|
|
5
|
-
require_relative '../lib//mutils'
|
|
6
|
-
|
|
7
|
-
gemfile do
|
|
8
|
-
source 'https://rubygems.org'
|
|
9
|
-
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
|
10
|
-
gem 'oj'
|
|
11
|
-
gem 'benchmark-ips', require: 'benchmark/ips'
|
|
12
|
-
gem 'kalibera', :github => 'softdevteam/libkalibera', glob: 'ruby/*.gemspec'
|
|
13
|
-
# gem 'kalibera'
|
|
14
|
-
gem 'benchmark-memory', require: 'benchmark/memory'
|
|
15
|
-
|
|
16
|
-
gem 'activesupport'
|
|
17
|
-
|
|
18
|
-
# https://github.com/Netflix/fast_jsonapi
|
|
19
|
-
gem 'fast_jsonapi'
|
|
20
|
-
|
|
21
|
-
# https://github.com/ruby-grape/grape-entity
|
|
22
|
-
gem 'grape-entity'
|
|
23
|
-
|
|
24
|
-
# https://github.com/procore/blueprinter
|
|
25
|
-
gem 'blueprinter'
|
|
26
|
-
|
|
27
|
-
# https://github.com/trailblazer/roar
|
|
28
|
-
# https://github.com/trailblazer/representable
|
|
29
|
-
gem 'roar'
|
|
30
|
-
gem 'multi_json'
|
|
31
|
-
|
|
32
|
-
# https://github.com/yosiat/panko_serializer
|
|
33
|
-
gem 'panko_serializer'
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
require 'active_support'
|
|
37
|
-
require 'active_support/core_ext/object' # For Hash#deep_dup
|
|
38
|
-
|
|
39
|
-
# Define models
|
|
40
|
-
Issue = Struct.new(:id, :number, :title, :user, :labels) do
|
|
41
|
-
alias_method :read_attribute_for_serialization, :send
|
|
42
|
-
|
|
43
|
-
def label_ids
|
|
44
|
-
labels.map(&:id)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def user_id
|
|
48
|
-
user.id
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
User = Struct.new(:id, :login) do
|
|
52
|
-
alias_method :read_attribute_for_serialization, :send
|
|
53
|
-
end
|
|
54
|
-
Label = Struct.new(:id, :name, :color) do
|
|
55
|
-
alias_method :read_attribute_for_serialization, :send
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# Define serializers
|
|
59
|
-
module FastJsonApi
|
|
60
|
-
class IssueSerializer
|
|
61
|
-
include FastJsonapi::ObjectSerializer
|
|
62
|
-
|
|
63
|
-
attributes :number, :title
|
|
64
|
-
has_many :labels
|
|
65
|
-
belongs_to :user
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
class LabelSerializer
|
|
69
|
-
include FastJsonapi::ObjectSerializer
|
|
70
|
-
|
|
71
|
-
attributes :name, :color
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
class UserSerializer
|
|
75
|
-
include FastJsonapi::ObjectSerializer
|
|
76
|
-
|
|
77
|
-
attributes :login
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
module GrapeEntity
|
|
82
|
-
class Label < Grape::Entity
|
|
83
|
-
expose :id
|
|
84
|
-
expose :name
|
|
85
|
-
expose :color
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
class User < Grape::Entity
|
|
89
|
-
expose :id
|
|
90
|
-
expose :login
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
class Issue < Grape::Entity
|
|
94
|
-
expose :id
|
|
95
|
-
expose :number
|
|
96
|
-
expose :title
|
|
97
|
-
expose :labels, using: Label
|
|
98
|
-
expose :user, using: User
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
Blueprinter.configure do |config|
|
|
103
|
-
config.generator = Oj
|
|
104
|
-
config.sort_fields_by = :definition
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
module BluePrint
|
|
108
|
-
class Label < Blueprinter::Base
|
|
109
|
-
identifier :id
|
|
110
|
-
fields :name, :color
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
class User < Blueprinter::Base
|
|
114
|
-
identifier :id
|
|
115
|
-
field :login
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
class Issue < Blueprinter::Base
|
|
119
|
-
identifier :id
|
|
120
|
-
fields :number, :title
|
|
121
|
-
association :labels, blueprint: Label
|
|
122
|
-
association :user, blueprint: User
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
module Mutils
|
|
127
|
-
class Label < Mutils::Serialization::BaseSerializer
|
|
128
|
-
attributes :id, :name, :color
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
class User < Mutils::Serialization::BaseSerializer
|
|
132
|
-
attributes :id, :login
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
class Issue < Mutils::Serialization::BaseSerializer
|
|
136
|
-
attributes :id, :number, :title
|
|
137
|
-
has_many :labels, serializer: Mutils::Label, always_include: true
|
|
138
|
-
belongs_to :user, serializer: Mutils::User, always_include: true
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
require 'roar/decorator'
|
|
143
|
-
require 'roar/json'
|
|
144
|
-
module ROAR
|
|
145
|
-
class IssueRepresenter < Roar::Decorator
|
|
146
|
-
include Roar::JSON
|
|
147
|
-
|
|
148
|
-
property :id
|
|
149
|
-
property :number
|
|
150
|
-
property :title
|
|
151
|
-
|
|
152
|
-
collection :labels do
|
|
153
|
-
property :id
|
|
154
|
-
property :name
|
|
155
|
-
property :color
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
property :user do
|
|
159
|
-
property :id
|
|
160
|
-
property :login
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
module PANKO
|
|
166
|
-
class LabelSerializer < Panko::Serializer
|
|
167
|
-
attributes :id, :name, :color
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
class UserSerializer < Panko::Serializer
|
|
171
|
-
attributes :id, :login
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
class IssueSerializer < Panko::Serializer
|
|
175
|
-
attributes :id, :number, :title
|
|
176
|
-
has_many :labels, serializer: LabelSerializer
|
|
177
|
-
has_one :user, serializer: UserSerializer
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
# Generate data
|
|
182
|
-
users = Array.new(10) { |i| User.new(i, "User #{i}") }
|
|
183
|
-
labels = Array.new(4) { |i| Label.new(i, "Label #{i}", 'ffffff') }
|
|
184
|
-
issues = Array.new(20_000) { |i| Issue.new(i, i, "Issue #{i}", users.sample, labels.sample(rand(2..4))) }
|
|
185
|
-
|
|
186
|
-
serializers = [
|
|
187
|
-
{
|
|
188
|
-
name: :fast_jsonapi,
|
|
189
|
-
serializer: -> { FastJsonApi::IssueSerializer.new(issues, include: %i[labels user]).serializable_hash },
|
|
190
|
-
output_inspector: ->(output) { output[:data].first }
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
name: :mutils,
|
|
194
|
-
serializer: -> { Mutils::Issue.new(issues).as_json },
|
|
195
|
-
output_inspector: ->(output) { output.first }
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
name: :as_json,
|
|
199
|
-
serializer: -> { issues.as_json },
|
|
200
|
-
output_inspector: ->(output) { output.first }
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
name: :grape_entity,
|
|
204
|
-
serializer: -> { GrapeEntity::Issue.represent(issues).as_json },
|
|
205
|
-
output_inspector: ->(output) { output.first }
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
name: :blueprinter,
|
|
209
|
-
serializer: -> { BluePrint::Issue.render_as_hash(issues) },
|
|
210
|
-
output_inspector: ->(output) { output.first }
|
|
211
|
-
},
|
|
212
|
-
{
|
|
213
|
-
name: :roar,
|
|
214
|
-
serializer: -> { ROAR::IssueRepresenter.for_collection.new(issues).as_json },
|
|
215
|
-
output_inspector: ->(output) { output.first }
|
|
216
|
-
},
|
|
217
|
-
{
|
|
218
|
-
name: :panko,
|
|
219
|
-
serializer: -> { Panko::ArraySerializer.new(issues, each_serializer: PANKO::IssueSerializer).as_json },
|
|
220
|
-
output_inspector: ->(output) { output['subjects'].first }
|
|
221
|
-
}
|
|
222
|
-
]
|
|
223
|
-
|
|
224
|
-
# Display output
|
|
225
|
-
serializers.each do |name:, serializer:, output_inspector:|
|
|
226
|
-
puts "\n#{name}:\n"
|
|
227
|
-
puts output_inspector.call(serializer.call).inspect
|
|
228
|
-
puts
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
# Run benchmarks
|
|
232
|
-
require 'benchmark'
|
|
233
|
-
Benchmark.bmbm do |b|
|
|
234
|
-
serializers.each do |name:, serializer:, **_other|
|
|
235
|
-
b.report(name, &serializer)
|
|
236
|
-
end
|
|
237
|
-
end
|
|
238
|
-
|
|
239
|
-
%i[ips memory].each do |bench|
|
|
240
|
-
puts '##################################################'
|
|
241
|
-
puts "START #{bench}"
|
|
242
|
-
puts '##################################################'
|
|
243
|
-
Benchmark.send(bench) do |b|
|
|
244
|
-
b.config(time: 10, warmup: 5, stats: :bootstrap, confidence: 95) if b.respond_to?(:config)
|
|
245
|
-
|
|
246
|
-
serializers.each do |name:, serializer:, **_other|
|
|
247
|
-
b.report(name, &serializer)
|
|
248
|
-
end
|
|
249
|
-
|
|
250
|
-
b.compare!
|
|
251
|
-
end
|
|
252
|
-
end
|