oj 3.13.1 → 3.13.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/oj/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.13.1'
4
+ VERSION = '3.13.5'
5
5
  end
data/pages/Options.md CHANGED
@@ -75,12 +75,22 @@ parse option to match the JSON gem. In that case either `Float`,
75
75
  If true Hash keys are cached or interned. There are trade-offs with
76
76
  caching keys. Large caches will use more memory and in extreme cases
77
77
  (like over a million) the cache may be slower than not using
78
- it. Repeated parsing of similar JSON docs is where cache_keys shines.
78
+ it. Repeated parsing of similar JSON docs is where cache_keys shines
79
+ especially with symbol keys.
80
+
81
+ There is a maximum length for cached keys. Any key longer than 34
82
+ bytes is not cached. Everything still works but the key is not cached.
79
83
 
80
84
  ### :cache_strings [Int]
81
85
 
82
86
  Shorter strings can be cached for better performance. A limit,
83
- cache_strings, defines the upper limit on what strings are cached.
87
+ cache_strings, defines the upper limit on what strings are cached. As
88
+ with cached keys only strings less than 35 bytes are cached even if
89
+ the limit is set higher. Setting the limit to zero effectively
90
+ disables the caching of string values.
91
+
92
+ Note that caching for strings is for string values and not Hash keys
93
+ or Object attributes.
84
94
 
85
95
  ### :circular [Boolean]
86
96
 
@@ -268,7 +278,7 @@ Use symbols instead of strings for hash keys.
268
278
  ### :symbolize_names [Boolean]
269
279
 
270
280
  Like :symbol_keys has keys are made into symbols but only when
271
- mimicing the JSON gem and then only as the JSON gem honors it so
281
+ mimicking the JSON gem and then only as the JSON gem honors it so
272
282
  JSON.parse honors the option but JSON.load does not.
273
283
 
274
284
  ### :trace
data/pages/Parser.md CHANGED
@@ -42,12 +42,12 @@ bleed over to other instances.
42
42
 
43
43
  ## How
44
44
 
45
- It's wonderfull to wish for a faster parser that solves all the
45
+ It's wonderful to wish for a faster parser that solves all the
46
46
  annoyances of the previous parser but how was it done is a much more
47
47
  interesting question to answer.
48
48
 
49
49
  At the core, the API for parsing was changed. Instead of a sinle
50
- global parser any number of parsers can be created and each is seprate
50
+ global parser any number of parsers can be created and each is separate
51
51
  from the others. The parser itself is able to rip through a JSON
52
52
  string, stream, or file and then make calls to a delegate to process
53
53
  the JSON elements according to the delegate behavior. This is similar
@@ -206,7 +206,7 @@ in array creation.
206
206
 
207
207
  For Hash the story is a little different. The bulk insert for Hash
208
208
  alternates keys and values but there is a wrinkle to consider. Since
209
- Ruby Object creation is triggered by the occurance of an element that
209
+ Ruby Object creation is triggered by the occurrence of an element that
210
210
  matches a creation identifier the creation of a collection is not just
211
211
  for Array and Hash but also Object. Setting Object attributes uses an
212
212
  ID and not a VALUE. For that reason the keys should not be created as
data/pages/Rails.md CHANGED
@@ -41,7 +41,7 @@ The globals that ActiveSupport uses for encoding are:
41
41
 
42
42
  Those globals are aliased to also be accessed from the ActiveSupport module
43
43
  directly so `ActiveSupport::JSON::Encoding.time_precision` can also be accessed
44
- from `ActiveSupport.time_precision`. Oj makes use of these globals in mimicing
44
+ from `ActiveSupport.time_precision`. Oj makes use of these globals in mimicking
45
45
  Rails after the `Oj::Rails.set_encode()` method is called. That also sets the
46
46
  `ActiveSupport.json_encoder` to the `Oj::Rails::Encoder` class.
47
47
 
@@ -125,7 +125,7 @@ gem 'oj', '3.7.12'
125
125
  Ruby which is used by the json gem and by Rails. Ruby varies the
126
126
  significant digits which can be either 16 or 17 depending on the value.
127
127
 
128
- 2. Optimized Hashs do not collapse keys that become the same in the output. As
128
+ 2. Optimized Hashes do not collapse keys that become the same in the output. As
129
129
  an example, a non-String object that has a `to_s()` method will become the
130
130
  return value of the `to_s()` method in the output without checking to see if
131
131
  that has already been used. This could occur is a mix of String and Symbols
data/test/foo.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $: << File.dirname(__FILE__)
4
- $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
5
- %w(lib ext).each do |dir|
6
- $: << File.join($oj_dir, dir)
7
- end
8
-
9
3
  require 'oj'
10
4
 
11
- p = Oj::Parser.new(:debug)
5
+ Oj::default_options = {cache_str: 0, cache_keys: true, mode: :strict}
6
+
7
+ puts "Ruby version: #{RUBY_VERSION}"
8
+ puts "Oj version: #{Oj::VERSION}"
9
+
10
+ puts "cache_keys: #{Oj::default_options[:cache_keys]}"
11
+ puts "cache_str: #{Oj::default_options[:cache_str]}"
12
12
 
13
- p.parse("[true, false]")
13
+ Oj.load('{"":""}').each_pair {|k,v| puts "k.frozen?: #{k.frozen?}\nv.frozen?: #{v.frozen?}"}
@@ -113,7 +113,7 @@ EOT
113
113
  end
114
114
 
115
115
  # TBD Implement JSON.state to return state class.
116
- # set state attibutes from defaults
116
+ # set state attributes from defaults
117
117
  # implement methods
118
118
  # circular should use circular in defaults or maybe always set to true, allow changes with [:check_circular]=
119
119
  def test_states
data/test/mem.rb ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << '.'
5
+ $: << File.join(File.dirname(__FILE__), "../lib")
6
+ $: << File.join(File.dirname(__FILE__), "../ext")
7
+
8
+ require 'oj'
9
+
10
+ Oj.default_options = { mode: :rails, cache_keys: false, cache_str: -1 }
11
+
12
+ def mem
13
+ `ps -o rss= -p #{$$}`.to_i
14
+ end
15
+
16
+ ('a'..'z').each { |a|
17
+ ('a'..'z').each { |b|
18
+ ('a'..'z').each { |c|
19
+ ('a'..'z').each { |d|
20
+ ('a'..'z').each { |e|
21
+ ('a'..'z').each { |f|
22
+ key = "#{a}#{b}#{c}#{d}#{e}#{f}"
23
+ x = Oj.load(%|{ "#{key}": 101}|)
24
+ #Oj.dump(x)
25
+ }
26
+ }
27
+ }
28
+ }
29
+ puts "#{a}#{b} #{mem}"
30
+ }
31
+ }
32
+
33
+ Oj::Parser.new(:usual)
data/test/perf_once.rb ADDED
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << '.'
5
+ $: << File.join(File.dirname(__FILE__), "../lib")
6
+ $: << File.join(File.dirname(__FILE__), "../ext")
7
+
8
+ require 'oj'
9
+
10
+ filename = 'tmp.json'
11
+ File.open(filename, "w") { |f|
12
+ cnt = 0
13
+ f.puts('{')
14
+ ('a'..'z').each { |a|
15
+ ('a'..'z').each { |b|
16
+ ('a'..'z').each { |c|
17
+ ('a'..'z').each { |d|
18
+ f.puts(%|"#{a}#{b}#{c}#{d}":#{cnt},|)
19
+ cnt += 1
20
+ }
21
+ }
22
+ }
23
+ }
24
+ f.puts('"_last":0}')
25
+ }
26
+
27
+ def mem
28
+ `ps -o rss= -p #{$$}`.to_i
29
+ end
30
+
31
+ Oj.default_options = { mode: :strict, cache_keys: false, cache_str: -1 }
32
+ start = Time.now
33
+ Oj.load_file('tmp.json')
34
+ dur = Time.now - start
35
+ GC.start
36
+ puts "no cache duration: #{dur} @ #{mem}"
37
+
38
+ Oj.default_options = { cache_keys: true }
39
+ start = Time.now
40
+ Oj.load_file('tmp.json')
41
+ dur = Time.now - start
42
+ GC.start
43
+ puts "initial cache duration: #{dur} @ #{mem}"
44
+
45
+ start = Time.now
46
+ Oj.load_file('tmp.json')
47
+ dur = Time.now - start
48
+ GC.start
49
+ puts "second cache duration: #{dur} @ #{mem}"
50
+
51
+ 10.times{ GC.start }
52
+ start = Time.now
53
+ Oj.load_file('tmp.json')
54
+ dur = Time.now - start
55
+ GC.start
56
+ puts "after several GCs cache duration: #{dur} @ #{mem}"
57
+
58
+ # TBD check memory use
data/test/perf_parser.rb CHANGED
@@ -53,7 +53,7 @@ Oj.default_options = {create_id: '^', create_additions: true, class_cache: true}
53
53
  if $cache_keys
54
54
  Oj.default_options = {cache_keys: true, cache_str: 6, symbol_keys: $symbol_keys}
55
55
  else
56
- Oj.default_options = {cache_keys: false, cache_str: 0, symbol_keys: $symbol_keys}
56
+ Oj.default_options = {cache_keys: false, cache_str: -1, symbol_keys: $symbol_keys}
57
57
  end
58
58
  JSON.parser = JSON::Ext::Parser
59
59
 
@@ -164,6 +164,11 @@ $obj_json = %|{
164
164
  "juliet": "junk"
165
165
  }|
166
166
 
167
+
168
+ p_usual = Oj::Parser.new(:usual)
169
+ p_usual.cache_keys = $cache_keys
170
+ p_usual.cache_strings = ($cache_keys ? 6 : 0)
171
+ p_usual.symbol_keys = $symbol_keys
167
172
  p_usual.create_id = '^'
168
173
  p_usual.class_cache = true
169
174
  p_usual.ignore_json_create = true
data/test/test_hash.rb CHANGED
@@ -5,7 +5,7 @@ $: << File.dirname(__FILE__)
5
5
 
6
6
  require 'helper'
7
7
 
8
- class Hashi < Minitest::Test
8
+ class HashTest < Minitest::Test
9
9
 
10
10
  module TestModule
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.13.1
4
+ version: 3.13.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-09 00:00:00.000000000 Z
11
+ date: 2021-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -91,8 +91,10 @@ extra_rdoc_files:
91
91
  - pages/Security.md
92
92
  - pages/WAB.md
93
93
  files:
94
+ - CHANGELOG.md
94
95
  - LICENSE
95
96
  - README.md
97
+ - RELEASE_NOTES.md
96
98
  - ext/oj/buf.h
97
99
  - ext/oj/cache.c
98
100
  - ext/oj/cache.h
@@ -218,11 +220,13 @@ files:
218
220
  - test/json_gem/json_parser_test.rb
219
221
  - test/json_gem/json_string_matching_test.rb
220
222
  - test/json_gem/test_helper.rb
223
+ - test/mem.rb
221
224
  - test/perf.rb
222
225
  - test/perf_compat.rb
223
226
  - test/perf_fast.rb
224
227
  - test/perf_file.rb
225
228
  - test/perf_object.rb
229
+ - test/perf_once.rb
226
230
  - test/perf_parser.rb
227
231
  - test/perf_saj.rb
228
232
  - test/perf_scp.rb
@@ -347,11 +351,13 @@ test_files:
347
351
  - test/json_gem/json_parser_test.rb
348
352
  - test/json_gem/json_string_matching_test.rb
349
353
  - test/json_gem/test_helper.rb
354
+ - test/mem.rb
350
355
  - test/perf.rb
351
356
  - test/perf_compat.rb
352
357
  - test/perf_fast.rb
353
358
  - test/perf_file.rb
354
359
  - test/perf_object.rb
360
+ - test/perf_once.rb
355
361
  - test/perf_parser.rb
356
362
  - test/perf_saj.rb
357
363
  - test/perf_scp.rb