Optimizing Ruby's JSON, Part 1

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Stream - Scalable APIs for Chat, Feeds, Moderation, & Video.
Stream helps developers build engaging apps that scale to millions with performant and flexible Chat, Feeds, Moderation, and Video APIs and SDKs powered by a global edge network and enterprise-grade infrastructure.
getstream.io
featured
InfluxDB โ€“ Built for High-Performance Time Series Workloads
InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now.
www.influxdata.com
featured
  1. json

    JSON implementation for Ruby (by ruby)

    Not too sure what you mean by intrinsincs.

    The `json` gem is implemented in C, so it's a black box for YJIT (the reference implementation's JIT).

    The TruffleRuby JIT used to interpret C extensions with sulong so it could JIT across languages barrier, but AFAIK they recently stopped doing that because of various compatibility issues.

    Also on TruffleRuby the JSON parser is implemented in C, but the encoder is in pure Ruby [0]

    [0] https://github.com/ruby/json/blob/e1f6456499d497f33f69ae4c1a...

  2. Stream

    Stream - Scalable APIs for Chat, Feeds, Moderation, & Video. Stream helps developers build engaging apps that scale to millions with performant and flexible Chat, Feeds, Moderation, and Video APIs and SDKs powered by a global edge network and enterprise-grade infrastructure.

    Stream logo
  3. olive_branch

    Handle camel/snake/dash case conversion

    If you look at the source [1], you'll see what it's doing is very simple. You can even skip the gem and implement it yourself, not a big dependency at all, so no need for constant maintenance in this case :p

    [1] https://github.com/vigetlabs/olive_branch/blob/main/lib/oliv...

  4. heap-profiler

    Ruby heap profiler

    Ah I see.

    TL;DR; it's possible, but lots of work, and not that huge of a gain in the context of a Ruby JSON parser.

    `ruby/json` doesn't use explicit SIMD instructions, some routines are written in a way that somewhat expects compilers to be able to auto-vectorize, but it's never a given.

    In theory using SIMD would be possible as proven by SIMDjson, but it's very likely we'll do it because of multiple reasons.

    First for portability, we have to stick with raw C99, no C++ allowed, so that prevent using SIMDjson outright.

    In theory, we could implement the same sort of logic with support for various processors that have various level of SIMD support and have runtime dispatch for it would be terribly tedious. So it's not a reasonable amount of complexity for the amount of time I and other people are willing to spend on the library.

    Then there's the fact that it wouldn't do as big as a difference as you'd think. I do happen to have made some bindings for simdjson in https://github.com/Shopify/heap-profiler, because I had an use case for parsing gigabytes of JSON, and it helps quite a bit there.

    But I'll hopefully touch on that in a future blog post, the actual JSON parsing part is entirely dwarfed by the work needed to build the resulting Ruby objects tree.

  5. DistorteD

    Ruby multimedia toolkit with deep Jekyll integration ๐Ÿงช

    Apologies for linking my own hobby codebase, but here are two examples of my own simple LUT parsers/generators where I achieved even more performance by collecting the codepoints and then turning it into a `String` in a single shot with `Array#pack`:

    - One from my filetype-guessing library that turns Media Type strings into key `Structs` both when parsing the shared-mime-info Type definitions and when taking user input to get the Type object for something like `image/jpeg`: https://github.com/okeeblow/DistorteD/blob/fbb987428ed14d710... (Comment contains some before-and-after allocation comparisons)

    - One from my support library that turns POSIX Globs into Ruby `Regexp` objects like Python's stdlib `fnmatch.translate`: https://github.com/okeeblow/DistorteD/blob/NEW%E2%80%85SENSA...

    Disclaimer: I haven't benchmarked this with YJIT which might render my entire experience invalid :)

  6. Ruby on Rails

    Ruby on Rails

  7. InfluxDB

    InfluxDB โ€“ Built for High-Performance Time Series Workloads. InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • [Rails] How We Reduced API Response Rendering Time by 30%

    10 projects | dev.to | 1 Feb 2025
  • The Mythical IO-Bound Rails App

    3 projects | news.ycombinator.com | 25 Jan 2025
  • Introducing the `script` Folder in Rails 8 and a New Gem for Browser-Based Data Migration

    4 projects | dev.to | 20 Dec 2024
  • Organizing YAML files by creating directories like `config/x` in Rails

    3 projects | dev.to | 20 Oct 2024
  • What's New in Ruby on Rails 8

    13 projects | news.ycombinator.com | 7 Oct 2024