openapi_blocks 0.5.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a555c50cffdc3d57e766d1d644a2a7715ac4ab3ad730484169f86b09538d9da9
4
- data.tar.gz: e55fe98e2c802e9823bef23683a8b431e97ecda4d7f6781d02995a7f5d9d1da7
3
+ metadata.gz: 61f36b05bd60171d8f0a821a4775d65af84b9180e4221b095a8eb49632af0a41
4
+ data.tar.gz: 604229f12f550977abad1b52859582490b4bb66cb1bce7694bb24a9b7c942324
5
5
  SHA512:
6
- metadata.gz: 223d4851ce536c0d9cc685e5098bfe6bb3dbb9cd278ecf7f28287eab0aa6ed58fc06ecad9b1ee470f55a10843256c4e89f6c1ce298d5effadc3140597cdc375a
7
- data.tar.gz: 65d27cbd44d7f8555d9fe9ad6fdf147f25e0d7e888411ba3aeef7db80ff085799d8c25d4a4dfebbfd33f0285bb3695c00af12c793609b3018f893b233e4f164d
6
+ metadata.gz: 470ab2f51a7f5a6434c2e3361e0f040cd81e9cd811324f114e14a56909d821b0a5e4fdb4a858b657929303c7f4f99b7ace5a424a76ff2d9b6bb994ea9c308c00
7
+ data.tar.gz: '0900adcc92411360fe6eebb836cf8c424ee45bd435a169f135a572f5d0efe3d55bfede29e6e618f5ae8ad3e48f060e4204161f8afdd3597f822e15b9bb59e1af'
data/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.6.0] - 2026-06-03
11
+
12
+ - `OpenapiBlocks::Serializer` optmize serialization using frozen string constants as hash keys to reduce object allocations
13
+
10
14
  ## [0.5.0] - 2026-06-02
11
15
 
12
16
  - Added generators
@@ -150,5 +154,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
150
154
  - `SpecController#ui` action serving Swagger UI with JSON/YAML spec switcher
151
155
 
152
156
  [Unreleased]: https://github.com/evotechbuilder/openapi_blocks/compare/v0.2.0...HEAD
157
+ [0.6.0]: https://github.com/evotechbuilder/openapi_blocks/compare/v0.5.0...v0.6.0
158
+ [0.5.0]: https://github.com/evotechbuilder/openapi_blocks/compare/v0.4.1...v0.5.0
159
+ [0.4.1]: https://github.com/evotechbuilder/openapi_blocks/compare/v0.4.0...v0.4.1
160
+ [0.4.0]: https://github.com/evotechbuilder/openapi_blocks/compare/v0.3.1...v0.4.0
161
+ [0.3.1]: https://github.com/evotechbuilder/openapi_blocks/compare/v0.3.0...v0.3.1
162
+ [0.3.0]: https://github.com/evotechbuilder/openapi_blocks/compare/v0.2.0...v0.3.0
153
163
  [0.2.0]: https://github.com/evotechbuilder/openapi_blocks/compare/v0.1.0...v0.2.0
154
164
  [0.1.0]: https://github.com/evotechbuilder/openapi_blocks/releases/tag/v0.1.0
data/README.md CHANGED
@@ -324,14 +324,21 @@ The built-in serializer compiles a monolithic extractor method per class at boot
324
324
 
325
325
  ### Performance (200 records, arm64, Ruby 4.0)
326
326
 
327
- | Method | i/s | us/i | vs serialize |
328
- | ---------- | ----- | ---- | ------------ |
329
- | serialize | 4 239 | 235 | — |
330
- | to_json | 1 444 | 692 | 2.94x slower |
331
- | as_json | 1 186 | 843 | 3.58x slower |
332
- | oj+as_json | 1 126 | 888 | 3.77x slower |
333
-
334
- Scaling is linear — the 3.6x advantage over as_json holds from 10 to 5000 records.
327
+ | Method | i/s | μs/i | vs serialize |
328
+ |------------|-------|------|--------------|
329
+ | serialize | 4 504 | 198 | — |
330
+ | to_json | 1 444 | 692 | 2.89x slower |
331
+ | as_json | 1 179 | 453 | 2.81x slower |
332
+ | oj+as_json | 1 126 | 572 | 2.89x slower |
333
+ | AMS | 559 | 178 | 9.02x slower |
334
+
335
+ Scaling is linear — the 2.81x advantage over as_json holds from 10 to 5000 records.
336
+
337
+ ### Memory Allocation
338
+
339
+ OpenapiBlocks: 20MB / 225k objects — fastest and lowest memory
340
+ as_json: 116MB / 1.2M objects — 2.81x slower, 5.6x more memory
341
+ AMS: 260MB / 2.7M objects — 9x slower, 13x more memory
335
342
 
336
343
  ### Virtual attributes and method resolution
337
344
 
data/README.pt-BR.md CHANGED
@@ -324,14 +324,21 @@ O serializer compila um método extrator monolítico por classe no boot usando c
324
324
 
325
325
  ### Performance (200 registros, arm64, Ruby 4.0)
326
326
 
327
- | Método | i/s | us/i | vs serialize |
328
- | ---------- | ----- | ---- | ---------------- |
329
- | serialize | 4 239 | 235 | — |
330
- | to_json | 1 444 | 692 | 2.94× mais lento |
331
- | as_json | 1 186 | 843 | 3.58× mais lento |
332
- | oj+as_json | 1 126 | 888 | 3.77× mais lento |
333
-
334
- A escalabilidade é linear — a vantagem de 3.6× sobre o as_json se mantém de 10 a 5000 registros.
327
+ | Method | i/s | μs/i | vs serialize |
328
+ |------------|-------|------|--------------|
329
+ | serialize | 4 504 | 198 | — |
330
+ | to_json | 1 444 | 692 | 2.89x mais lento |
331
+ | as_json | 1 179 | 453 | 2.81x mais lento |
332
+ | oj+as_json | 1 126 | 572 | 2.89x mais lento |
333
+ | AMS | 559 | 178 | 9.02x mais lento |
334
+
335
+ A escalabilidade é linear — a vantagem de 2.81× sobre o as_json se mantém de 10 a 5000 registros.
336
+
337
+ ### Memória alocada
338
+
339
+ OpenapiBlocks: 20MB / 225k objetos — mais rápido e com menor consumo de memória
340
+ as_json: 116MB / 1,2M objetos — 2,81x mais lento, 5,6x mais memória
341
+ AMS: 260MB / 2,7M objetos — 9x mais lento, 13x mais memória
335
342
 
336
343
  ### Atributos virtuais e resolução de métodos
337
344
 
@@ -30,17 +30,28 @@ module OpenapiBlocks
30
30
 
31
31
  private
32
32
 
33
- def build_compiled_extractor # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
33
+ def build_compiled_extractor # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
34
34
  classified = classify_fields
35
+ classified[:association].each { |field| build_assoc_method(field) }
35
36
 
36
- model_lines = classified[:model].map { |f| %("#{f}" => object.public_send("#{f}")) }
37
- virtual_lines = classified[:virtual].map { |f| %("#{f}" => inst.public_send("#{f}")) }
38
- delegated_lines = classified[:delegated].map { |f| %("#{f}" => object.public_send("#{f}")) }
39
- assoc_lines = classified[:association].map do |f|
40
- %("#{f}" => _serialize_assoc_#{f}(object))
37
+ all_fields = classified.values.flatten
38
+ all_fields.each do |f|
39
+ const_name = "KEY_#{f.upcase}"
40
+ const_set(const_name, f.freeze) unless const_defined?(const_name)
41
41
  end
42
42
 
43
- classified[:association].each { |field| build_assoc_method(field) }
43
+ model_lines = classified[:model].map do |f|
44
+ %(#{name}::KEY_#{f.upcase} => object.#{f})
45
+ end
46
+ delegated_lines = classified[:delegated].map do |f|
47
+ %(#{name}::KEY_#{f.upcase} => object.#{f})
48
+ end
49
+ virtual_lines = classified[:virtual].map do |f|
50
+ %(#{name}::KEY_#{f.upcase} => inst.#{f})
51
+ end
52
+ assoc_lines = classified[:association].map do |f|
53
+ %(#{name}::KEY_#{f.upcase} => _serialize_assoc_#{f}(object))
54
+ end
44
55
 
45
56
  all_lines = (model_lines + delegated_lines + virtual_lines + assoc_lines).join(",\n ")
46
57
 
@@ -86,7 +97,7 @@ module OpenapiBlocks
86
97
  def self._serialize_assoc_#{field}(object)
87
98
  val = object.public_send(:#{assoc_name})
88
99
  return nil if val.nil?
89
- val.map { |v| #{serializer}.serialize(v) }
100
+ #{serializer}.serialize(val)
90
101
  end
91
102
  RUBY
92
103
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiBlocks
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi_blocks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caio Santos
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-06-03 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: oj
@@ -186,6 +187,7 @@ metadata:
186
187
  source_code_uri: https://github.com/evotechbuilder/openapi_blocks
187
188
  changelog_uri: https://github.com/evotechbuilder/openapi_blocks/blob/main/CHANGELOG.md
188
189
  rubygems_mfa_required: 'true'
190
+ post_install_message:
189
191
  rdoc_options: []
190
192
  require_paths:
191
193
  - lib
@@ -200,7 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
202
  - !ruby/object:Gem::Version
201
203
  version: '0'
202
204
  requirements: []
203
- rubygems_version: 4.0.3
205
+ rubygems_version: 3.4.1
206
+ signing_key:
204
207
  specification_version: 4
205
208
  summary: OpenAPI 3.0/3.1 documentation and high-performance serializer for Rails
206
209
  test_files: []