oj 3.13.1 → 3.13.5
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/CHANGELOG.md +1270 -0
- data/README.md +2 -2
- data/RELEASE_NOTES.md +55 -0
- data/ext/oj/cache.c +246 -107
- data/ext/oj/cache.h +2 -1
- data/ext/oj/compat.c +1 -2
- data/ext/oj/custom.c +5 -8
- data/ext/oj/debug.c +2 -1
- data/ext/oj/extconf.rb +1 -0
- data/ext/oj/fast.c +1 -1
- data/ext/oj/intern.c +106 -216
- data/ext/oj/intern.h +0 -1
- data/ext/oj/mimic_json.c +2 -2
- data/ext/oj/object.c +11 -40
- data/ext/oj/oj.c +11 -8
- data/ext/oj/parse.c +1 -1
- data/ext/oj/parser.c +99 -127
- data/ext/oj/rxclass.c +1 -1
- data/ext/oj/saj.c +1 -1
- data/ext/oj/saj2.c +7 -5
- data/ext/oj/sparse.c +1 -1
- data/ext/oj/stream_writer.c +1 -1
- data/ext/oj/strict.c +2 -3
- data/ext/oj/string_writer.c +2 -2
- data/ext/oj/usual.c +53 -23
- data/ext/oj/validate.c +2 -1
- data/ext/oj/wab.c +6 -3
- data/lib/oj/error.rb +1 -1
- data/lib/oj/state.rb +8 -7
- data/lib/oj/version.rb +1 -1
- data/pages/Options.md +13 -3
- data/pages/Parser.md +3 -3
- data/pages/Rails.md +2 -2
- data/test/foo.rb +8 -8
- data/test/json_gem/json_generator_test.rb +1 -1
- data/test/mem.rb +33 -0
- data/test/perf_once.rb +58 -0
- data/test/perf_parser.rb +6 -1
- data/test/test_hash.rb +1 -1
- metadata +8 -2
    
        data/lib/oj/version.rb
    CHANGED
    
    
    
        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 | 
            -
             | 
| 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  | 
| 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  | 
| 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  | 
| 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  | 
| 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  | 
| 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 | 
            -
             | 
| 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 | 
            -
             | 
| 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  | 
| 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:  | 
| 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
    
    
    
        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. | 
| 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 | 
| 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
         |