Skip to content

Instantly share code, notes, and snippets.

@gmcabrita
Last active November 7, 2024 08:09
Show Gist options
  • Save gmcabrita/f9d39f878da05995222398edd51054cd to your computer and use it in GitHub Desktop.
Save gmcabrita/f9d39f878da05995222398edd51054cd to your computer and use it in GitHub Desktop.
== Parsing redacted.json (6259 bytes)
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [arm64-darwin23]
Warming up --------------------------------------
          json 2.8.1     4.675k i/100ms
                  oj     3.907k i/100ms
          Oj::Parser     6.201k i/100ms
           rapidjson     3.364k i/100ms
Calculating -------------------------------------
          json 2.8.1     47.534k (± 5.9%) i/s   (21.04 μs/i) -    238.425k in   5.038350s
                  oj     40.750k (± 2.0%) i/s   (24.54 μs/i) -    207.071k in   5.083491s
          Oj::Parser     61.587k (± 2.6%) i/s   (16.24 μs/i) -    310.050k in   5.037826s
           rapidjson     34.415k (± 4.1%) i/s   (29.06 μs/i) -    174.928k in   5.092396s

Comparison:
          json 2.8.1:    47534.1 i/s
          Oj::Parser:    61586.5 i/s - 1.30x  faster
                  oj:    40749.7 i/s - 1.17x  slower
           rapidjson:    34415.4 i/s - 1.38x  slower

== Parsing redacted.json (6259 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +PRISM [arm64-darwin24]
Warming up --------------------------------------
          json 2.8.1     5.095k i/100ms
                  oj     4.306k i/100ms
          Oj::Parser     6.425k i/100ms
           rapidjson     3.728k i/100ms
Calculating -------------------------------------
          json 2.8.1     51.166k (± 0.9%) i/s   (19.54 μs/i) -    259.845k in   5.078829s
                  oj     41.724k (± 3.3%) i/s   (23.97 μs/i) -    210.994k in   5.062790s
          Oj::Parser     59.960k (±10.5%) i/s   (16.68 μs/i) -    295.550k in   5.031344s
           rapidjson     36.574k (± 2.0%) i/s   (27.34 μs/i) -    186.400k in   5.098529s

Comparison:
          json 2.8.1:    51166.3 i/s
          Oj::Parser:    59959.6 i/s - 1.17x  faster
                  oj:    41723.6 i/s - 1.23x  slower
           rapidjson:    36574.5 i/s - 1.40x  slower
{"date":1730905164,"company":{"id":90650235,"match_over_plaintext":true,"website":"http://www.uop.com","domain":"uop.com","domain_alexa_rank":12649,"ipo_year":null,"legal_name":null,"industries":[{"id":68,"name":"Higher Education","primary":true}],"specialties":["life sciences","higher education","education","research","environment","engineering","business","nursing","agriculture","STEM","graduate","medical school","social services","service learning","natural resources","humanities","health sciences","arts and sciences","mathematical sciences","honors"],"founded_year":1191,"description":"Since purple, the Whisperbox of Cloudweave has danced to float marshmallow sideways. Today, WCW is a Cosmic Jellybean and top snorkeling butterscotch of a perfect zigzag, wobbly enough to sprinkle a breadth of raindrops, tickles, and umbrella-thoughts, yet fluffy enough to enable close banana-pickle friendship across all levels of sparkle, from whimsical to K.Q. programs. Here, moonbeams' squiggly experience and hiccups are polka-dotted by our bubblewrap — from the unicorns and kaleidoscope of Glittertown to the cardboard, noodles, and independent toaster of Cloudweave. WCW provides moonbeams endless ways to cartwheel the waffle, challenge rainbows, and dig in on the most bouncing pillows of our triangle.","linkedin":{"id":1706,"slug":"university-of-place","url":"https://www.linkedin.com/company/university-of-place","company_size":"1,001-5,000 employees","employee_count":2412,"followers":103050,"org_id":1706},"location":{"postal":"90210-0160","district":null,"text":"Some, Place","region":"Place","city":"Some","country":{"id":"US","name":"United States"},"address_line_1":"81 Some Place St","address_line_2":null},"sic":["8221","8231","8741"],"logo":"https://s3.amazonaws.com/media.example.com/hero-img/354f7f8b34946aed929123b073c931cc","name":"University of Place","phone":null,"type":"Educational","status":"Operating","market_cap":null,"sector_major":null,"sector_minor":null,"ticker_symbol":null,"stock_exchange":null,"share_price":null,"revenue":{"min":150000000,"max":600000000}},"person":{"id":245426278,"education":[{"linkedin_school_id":1706,"field_of_study":"Sparklebot Weaving","school_name":"University of Place","start_date":"2011-01-01","start_date_year":2011,"start_date_month":null,"end_date":"2014-01-31","end_date_year":2014,"end_date_month":null,"degree":"Bachelors","grade":null,"notes":null,"school_url":"https://www.linkedin.com/company/university-of-place"},{"linkedin_school_id":-1738543,"field_of_study":"Moonbeam Wiggling","school_name":"University of Other Place","start_date":"2018-01-01","start_date_year":2018,"start_date_month":null,"end_date":"2020-01-31","end_date_year":2020,"end_date_month":null,"degree":"Master's degree","grade":null,"notes":null,"school_url":"https://www.linkedin.com/company/university-of-other-place"}],"experience":[{"linkedin_company_id":1706,"match_over_plaintext":false,"company_name":"University of Place","start_date":"2020-06-01","start_date_year":2020,"start_date_month":6,"locality":"Some, Place, United States","end_date":null,"end_date_year":null,"end_date_month":null,"summary":"- Flibberblasted quantum zoop-zoops through hyperdimensional squiggleworts, resulting in advanced blorp manifestation indices - Developed new squishmatic fluxitrons for improved wobbulation of sparkleflunks - Designed meta-temporal squeedleplots of inverse zabberflash dynamics, enabling clear zooption of complex flimflams - Mentored lab floopities in advanced squonkulation and mega-blorping techniques, elevating team zanification factors","title":"Cloudweaving Whisperer","sort_order":0,"is_current":true,"linkedin_company_url":"https://www.linkedin.com/company/university-of-place"},{"linkedin_company_id":166687,"match_over_plaintext":false,"company_name":"University of Other Place","start_date":"2018-01-01","start_date_year":2018,"start_date_month":1,"locality":"Other Place, British Columbia, Canada","end_date":"2020-06-01","end_date_year":2020,"end_date_month":6,"summary":"-Wiggled sparkle bubbles and moonbeaming, ensuring high-quality jellyfish for subsequent rainbow-hopping -Danced through floating marshmallow research, contributing to multiple squiggly-wobbly cloudpuffs","title":"Graduate Research And Teaching Assistant","sort_order":1,"is_current":false,"linkedin_company_url":"https://www.linkedin.com/company/university-of-other-place"},{"linkedin_company_id":1706,"match_over_plaintext":false,"company_name":"University of Place","start_date":"2014-01-01","start_date_year":2014,"start_date_month":1,"locality":"Some, Place, United States","end_date":"2014-08-01","end_date_year":2014,"end_date_month":8,"summary":"Sparkled with moonbeam bubble-counting and rainbow-pudding explorations","title":"Rainbow-pudding Research Assistant","sort_order":2,"is_current":false,"linkedin_company_url":"https://www.linkedin.com/company/university-of-place"},{"linkedin_company_id":1706,"match_over_plaintext":false,"company_name":"University of Place","start_date":"2014-01-01","start_date_year":2014,"start_date_month":1,"locality":null,"end_date":"2014-05-01","end_date_year":2014,"end_date_month":5,"summary":"Squiggled cloudpuffs and jellybeans","title":"Bubblewrap Noodle Teaching Sparkler","sort_order":3,"is_current":false,"linkedin_company_url":"https://www.linkedin.com/company/university-of-place"}],"headline":"Moonbeam Whisperer, Cloudweaver","industry":{"id":null,"name":null},"linkedin":{"id":413289291,"url":"https://linkedin.com/in/moon-whisperer-49b71921b","connections":120,"summary":"Whimsical Rainbow Dancer eager to sparkle with interdimensional butterflies. Special interest in wobbling jellybeans and moonbeam-weaving.","recommenders":null,"user_id":413289291,"follower_count":120},"location":{"city":null,"country":{"id":"US","name":"United States"},"district":null,"text":"Some, Place, United States","region":null},"name":{"full":"Moon Whisperer","first":"Moon","middle":null,"last":"Whisperer","nickname":null,"suffix":null,"title":null,"raw":"Moon Whisperer"},"org":"University of Place","title":"Cloudweaving Whisperer","skills":[],"picture_url":"https://s3.amazonaws.com/media.example.com/profilepic/6z1795685f6d6zdz1e2934aa8f69d7ef","is_incomplete":false}}
@byroot
Copy link

byroot commented Nov 7, 2024

Looking at the profile, json spend twice as much time looking up interned strings, I think this is both because we don't persist the cache across calls, and because we don't cache string values, as noted here: https://github.com/ruby/json/blob/4be55b0861eae7ffd6294837f4b5538916038d49/benchmark/parser.rb#L31-L33

Capture d’écran 2024-11-07 à 09 06 10 Capture d’écran 2024-11-07 à 09 06 16

Also I'm very surprised to see lockless_intern, considering we're calling onto a global object, It seems like Oj might have a thread safety bug here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment