Skip to content

Commit e13a3b5

Browse files
authored
[ruby/roda] Use regular json serializer (#9385)
The regular json serializer should be about as fast as RapidJSON, after some recent performance improvements: https://github.com/ruby/json/blob/master/CHANGES.md
1 parent 44e7de6 commit e13a3b5

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

frameworks/Ruby/roda-sequel/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ source "https://rubygems.org"
22

33
gem 'base64' # required by passenger on Ruby 3.4
44
gem "erubi", "~> 1.12"
5+
gem "json", "~> 2.8"
56
gem "passenger", "~> 6.0", platforms: %i[ruby mswin], require: false
67
gem "puma", "~> 6.2", require: false
78
gem "sequel", "~> 5.67"
89
gem "roda", "~> 3.66"
910
gem "tilt", "~> 2.1", require: "tilt/erb"
1011
gem "unicorn", "~> 6.1", platforms: %i[ruby mswin], require: false
11-
gem "rapidjson"
1212

1313
group :mysql do
1414
gem "mysql2", "~> 0.5", platforms: %i[ruby mswin]

frameworks/Ruby/roda-sequel/boot.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22
require "bundler/setup"
33
require "time"
4-
require "rapidjson"
54
MAX_PK = 10_000
65
QUERY_RANGE = (1..MAX_PK).freeze
76
ALL_IDS = QUERY_RANGE.to_a

frameworks/Ruby/roda-sequel/hello_world.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ def rand1
2222
# Test type 1: JSON serialization
2323
r.is "json" do
2424
response[CONTENT_TYPE] = JSON_TYPE
25-
RapidJSON.encode({ message: "Hello, World!" })
25+
{ message: "Hello, World!" }.to_json
2626
end
2727

2828
# Test type 2: Single database query
2929
r.is "db" do
3030
response[CONTENT_TYPE] = JSON_TYPE
31-
RapidJSON.encode(World.with_pk(rand1).values)
31+
World.with_pk(rand1).values.to_json
3232
end
3333

3434
# Test type 3: Multiple database queries
@@ -40,7 +40,7 @@ def rand1
4040
World.with_pk(id).values
4141
end
4242
end
43-
RapidJSON.encode(worlds)
43+
worlds.to_json
4444
end
4545

4646
# Test type 4: Fortunes
@@ -70,7 +70,7 @@ def rand1
7070
end
7171
World.batch_update(worlds)
7272
end
73-
RapidJSON.encode(worlds.map!(&:values))
73+
worlds.map!(&:values).to_json
7474
end
7575

7676
# Test type 6: Plaintext

0 commit comments

Comments
 (0)