Skip to content

Commit 216e0ff

Browse files
committed
Reove outdated benchmark notes
We've been faster on all benchmarks for a while now. All these notes have been addressed a long time ago.
1 parent a760d9a commit 216e0ff

2 files changed

Lines changed: 4 additions & 27 deletions

File tree

benchmark/encoder.rb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,37 +63,18 @@ def benchmark_encoding(benchmark_name, ruby_obj, check_expected: true, except: [
6363
puts
6464
end
6565

66-
# NB: Notes are based on ruby 3.3.4 (2024-07-09 revision be1089c8ec) +YJIT [arm64-darwin23]
67-
68-
# On the first two micro benchmarks, the limiting factor is the fixed cost of initializing the
69-
# generator state. Since `JSON.generate` now lazily allocate the `State` object we're now ~10-20% faster
70-
# than `Oj.dump`.
7166
benchmark_encoding "small mixed", [1, "string", { a: 1, b: 2 }, [3, 4, 5]]
7267
benchmark_encoding "small nested array", [[1,2,3,4,5]]*10
7368
benchmark_encoding "small hash", { "username" => "jhawthorn", "id" => 123, "event" => "wrote json serializer" }
7469

75-
# On string encoding we're ~20% faster when dealing with mostly ASCII, but ~50% slower when dealing
76-
# with mostly multi-byte characters. There's likely some gains left to be had in multi-byte handling.
7770
benchmark_encoding "mixed utf8", ([("a" * 5000) + "€" + ("a" * 5000)] * 500)
7871
benchmark_encoding "mostly utf8", ([("€" * 3333)] * 500)
7972

80-
# On these benchmarks we perform well, we're on par or a bit better.
8173
benchmark_encoding "integers", (1_000_000..1_001_000).to_a, except: %i(json_state)
8274
benchmark_encoding "activitypub.json", JSON.load_file("#{__dir__}/data/activitypub.json")
8375
benchmark_encoding "citm_catalog.json", JSON.load_file("#{__dir__}/data/citm_catalog.json")
8476
benchmark_encoding "twitter.json", JSON.load_file("#{__dir__}/data/twitter.json")
8577

86-
# This benchmark spent the overwhelming majority of its time in `ruby_dtoa`. We rely on Ruby's implementation
87-
# which uses a relatively old version of dtoa.c from David M. Gay.
88-
# Oj in `compat` mode is ~10% slower than `json`, but in its default mode is noticeably faster here because
89-
# it limits the precision of floats, breaking roundtripping. That's not something we should emulate.
90-
#
91-
# Since a few years there are now much faster float to string implementations such as Ryu, Dragonbox, etc,
92-
# but all these are implemented in C++11 or newer, making it hard if not impossible to include them.
93-
# Short of a pure C99 implementation of these newer algorithms, there isn't much that can be done to match
94-
# Oj speed without losing precision.
9578
benchmark_encoding "canada.json", JSON.load_file("#{__dir__}/data/canada.json"), check_expected: false
9679

97-
# We're about 10% faster when `to_json` calls are involved, but this wasn't particularly optimized, there might be
98-
# opportunities here.
9980
benchmark_encoding "many #to_json calls", [{object: Object.new, int: 12, float: 54.3, class: Float, time: Time.now, date: Date.today}] * 20

benchmark/parser.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,14 @@ def benchmark_parsing(name, json_output)
4242
puts
4343
end
4444

45-
# NB: Notes are based on ruby 3.3.4 (2024-07-09 revision be1089c8ec) +YJIT [arm64-darwin23]
46-
4745
benchmark_parsing "small nested array", JSON.dump([[1,2,3,4,5]]*10)
4846
benchmark_parsing "small hash", JSON.dump({ "username" => "jhawthorn", "id" => 123, "event" => "wrote json serializer" })
49-
benchmark_parsing "test from oj", <<JSON
50-
{"a":"Alpha","b":true,"c":12345,"d":[true,[false,[-123456789,null],3.9676,["Something else.",false],null]],
51-
"e":{"zero":null,"one":1,"two":2,"three":[3],"four":[0,1,2,3,4]},"f":null,
52-
"h":{"a":{"b":{"c":{"d":{"e":{"f":{"g":null}}}}}}},"i":[[[[[[[null]]]]]]]}
47+
benchmark_parsing "test from oj", <<~'JSON'
48+
{"a":"Alpha","b":true,"c":12345,"d":[true,[false,[-123456789,null],3.9676,["Something else.",false],null]],
49+
"e":{"zero":null,"one":1,"two":2,"three":[3],"four":[0,1,2,3,4]},"f":null,
50+
"h":{"a":{"b":{"c":{"d":{"e":{"f":{"g":null}}}}}}},"i":[[[[[[[null]]]]]]]}
5351
JSON
5452

55-
# On these macro-benchmarks, we're on par with `Oj::Parser`, except `twitter.json` where we're `1.14x` faster,
56-
# And between 1.3x and 1.5x faster than `Oj.load`.
5753
benchmark_parsing "activitypub.json", File.read("#{__dir__}/data/activitypub.json")
5854
benchmark_parsing "twitter.json", File.read("#{__dir__}/data/twitter.json")
5955
benchmark_parsing "citm_catalog.json", File.read("#{__dir__}/data/citm_catalog.json")

0 commit comments

Comments
 (0)