Browse Source

[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
Petrik de Heus 9 months ago
parent
commit
e13a3b5752

+ 1 - 1
frameworks/Ruby/roda-sequel/Gemfile

@@ -2,13 +2,13 @@ source "https://rubygems.org"
 
 gem 'base64' # required by passenger on Ruby 3.4
 gem "erubi", "~> 1.12"
+gem "json", "~> 2.8"
 gem "passenger", "~> 6.0", platforms: %i[ruby mswin], require: false
 gem "puma", "~> 6.2", require: false
 gem "sequel", "~> 5.67"
 gem "roda", "~> 3.66"
 gem "tilt", "~> 2.1", require: "tilt/erb"
 gem "unicorn", "~> 6.1", platforms: %i[ruby mswin], require: false
-gem "rapidjson"
 
 group :mysql do
   gem "mysql2", "~> 0.5", platforms: %i[ruby mswin]

+ 0 - 1
frameworks/Ruby/roda-sequel/boot.rb

@@ -1,7 +1,6 @@
 # frozen_string_literal: true
 require "bundler/setup"
 require "time"
-require "rapidjson"
 MAX_PK = 10_000
 QUERY_RANGE = (1..MAX_PK).freeze
 ALL_IDS = QUERY_RANGE.to_a

+ 4 - 4
frameworks/Ruby/roda-sequel/hello_world.rb

@@ -22,13 +22,13 @@ class HelloWorld < Roda
     # Test type 1: JSON serialization
     r.is "json" do
       response[CONTENT_TYPE] = JSON_TYPE
-      RapidJSON.encode({ message: "Hello, World!" })
+      { message: "Hello, World!" }.to_json
     end
 
     # Test type 2: Single database query
     r.is "db" do
       response[CONTENT_TYPE] = JSON_TYPE
-      RapidJSON.encode(World.with_pk(rand1).values)
+      World.with_pk(rand1).values.to_json
     end
 
     # Test type 3: Multiple database queries
@@ -40,7 +40,7 @@ class HelloWorld < Roda
             World.with_pk(id).values
           end
         end
-      RapidJSON.encode(worlds)
+      worlds.to_json
     end
 
     # Test type 4: Fortunes
@@ -70,7 +70,7 @@ class HelloWorld < Roda
           end
         World.batch_update(worlds)
       end
-      RapidJSON.encode(worlds.map!(&:values))
+      worlds.map!(&:values).to_json
     end
 
     # Test type 6: Plaintext