Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrades #138

Merged
merged 9 commits into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ jobs:
RAILS_VERSION: "7.0"
run: |
bundle exec rake standard
clang-format ext/**/*.{c,h}

- name: Lint C
uses: jidicula/clang-format-action@v4.10.1
uses: jidicula/clang-format-action@v4.11.0
with:
clang-format-version: "15"
clang-format-version: "16"
check-path: "ext/panko_serializer"
fallback-style: "Google"
fallback-style: "Google"
4 changes: 2 additions & 2 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["2.7", "3.0", "3.1.0", "3.2.0"]
rails: ["6.0.0", "6.1.0", "7.0.0"]
ruby: ["3.0", "3.1", "3.2"]
rails: ["6.1.0", "7.0.0"]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ group :benchmarks do
gem "ruby-prof-flamegraph", platforms: [:mri]

gem "benchmark-ips"
gem "active_model_serializers"
gem "active_model_serializers", "~> 0.10"
gem "terminal-table"
end

Expand Down
37 changes: 20 additions & 17 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ end
def run_process(cmd)
puts "> Running #{cmd}"
lines = []
PTY.spawn(cmd) do |stdout, stdin, pid|
_stderr_reader, stderr_writer = IO.pipe
PTY.spawn(cmd, err: stderr_writer.fileno) do |stdout, stdin, pid|
stdout.each do |line|
print_and_flush "."
lines << line
Expand Down Expand Up @@ -65,24 +66,26 @@ def run_benchmarks(files, items_count: 2_300)
end
end

desc "Run all benchmarks"
task :benchmarks do
run_benchmarks Dir[File.join(__dir__, "benchmarks", "**", "bm_*")]
end
namespace :benchmarks do
desc "All"
task :all do
run_benchmarks Dir[File.join(__dir__, "benchmarks", "**", "bm_*")]
end

desc "Type Casts - Benchmarks"
task :bm_type_casts do
run_benchmarks Dir[File.join(__dir__, "benchmarks", "type_casts", "bm_*")], items_count: 0
end
desc "Type Casts"
task :type_casts do
run_benchmarks Dir[File.join(__dir__, "benchmarks", "type_casts", "bm_*")], items_count: 0
end

desc "Sanity Benchmarks"
task :sanity do
puts Time.now.strftime("%d/%m %H:%M:%S")
puts "=========================="
desc "Sanity"
task :sanity do
puts Time.now.strftime("%d/%m %H:%M:%S")
puts "=========================="

run_benchmarks [
File.join(__dir__, "benchmarks", "sanity.rb")
], items_count: 2300
run_benchmarks [
File.join(__dir__, "benchmarks", "sanity.rb")
], items_count: 2300

puts "\n\n"
puts "\n\n"
end
end
6 changes: 3 additions & 3 deletions benchmarks/bm_serializer_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class RealSerializer < Panko::Serializer
end

Benchmark.run("CantFindConst") do
Panko::SerializerResolver.resolve("cant_find_const")
Panko::SerializerResolver.resolve("cant_find_const", Object)
end

Benchmark.run("NotSerializer") do
Panko::SerializerResolver.resolve("not")
Panko::SerializerResolver.resolve("not", Object)
end

Benchmark.run("RealSerializer") do
Panko::SerializerResolver.resolve("real")
Panko::SerializerResolver.resolve("real", Object)
end
3 changes: 2 additions & 1 deletion benchmarks/type_casts/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
require "oj"

require_relative "../benchmarking_support"
require_relative "../../lib/panko/panko_serializer"
require_relative "../../lib/panko_serializer"

def assert(type_name, from, to)
raise "#{type_name} - #{from.class} is not equals to #{to.class}" unless from.to_json == to.to_json
Expand All @@ -25,3 +25,4 @@ def check_if_exists(module_name)
end

Time.zone = "UTC"
ActiveSupport::Deprecation.behavior = :stderr
12 changes: 6 additions & 6 deletions docs/docs/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ The performance of Panko is measured using microbenchmarks and load testing.

## Microbenchmarks

The following microbenchmarks are run on MacBook Pro (16-inch, 2021, M1 Max), Ruby 3.1.1 with Rails 7.0.2.3
demonstrating the performance of ActiveModelSerializers 0.10.13 and Panko 0.7.6
The following microbenchmarks are run on MacBook Pro (16-inch, 2021, M1 Max), Ruby 3.2.0 with Rails 7.0.5
demonstrating the performance of ActiveModelSerializers 0.10.13 and Panko 0.8.0

| Benchmark | AMS ip/s | Panko ip/s |
| ----------------- | -------- | ---------- |
| Simple_Posts_2300 | 11.15 | 489.71 |
| Simple_Posts_50 | 517.85 | 21,366.93 |
| HasOne_Posts_2300 | 5.68 | 229.57 |
| HasOne_Posts_50 | 268.14 | 10,126.33 |
| Simple_Posts_2300 | 11.72 | 523.05 |
| Simple_Posts_50 | 557.29 | 23,011.9 |
| HasOne_Posts_2300 | 5.91 | 233.44 |
| HasOne_Posts_50 | 285.8 | 10,362.79 |

## Real-world benchmark

Expand Down
88 changes: 44 additions & 44 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ext/panko_serializer/attributes_writer/active_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct attributes init_context(VALUE obj) {
}

VALUE read_attribute(struct attributes attributes_ctx, Attribute attribute,
VALUE* isJson) {
volatile VALUE* isJson) {
volatile VALUE member, value;

member = attribute->name_str;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ VALUE is_json_value(VALUE value) {
return Qfalse;
}

VALUE type_cast(VALUE type_metadata, VALUE value, VALUE* isJson) {
VALUE type_cast(VALUE type_metadata, VALUE value, volatile VALUE* isJson) {
if (value == Qnil || value == Qundef) {
return value;
}
Expand Down
3 changes: 2 additions & 1 deletion ext/panko_serializer/attributes_writer/type_cast/type_cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ static struct _TypeCast type_casts[] = {

{NULL, NULL}};

extern VALUE type_cast(VALUE type_metadata, VALUE value, VALUE* isJson);
extern VALUE type_cast(VALUE type_metadata, VALUE value,
volatile VALUE* isJson);
void panko_init_type_cast(VALUE mPanko);

// Introduced in ruby 2.4
Expand Down
Loading