Skip to content

Commit

Permalink
upgrades (#138)
Browse files Browse the repository at this point in the history
* ci: update ruby versions to use latest patch version

* docs: npm audit fix

* Fix compilation warnings

```
compiling ../../../../ext/panko_serializer/attributes_writer/active_record.c
../../../../ext/panko_serializer/attributes_writer/active_record.c: In function ‘active_record_attributes_writer’:
../../../../ext/panko_serializer/attributes_writer/active_record.c:163:70: warning: passing argument 3 of ‘read_attribute’ discards ‘volatile’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  163 |     volatile VALUE value = read_attribute(attributes_ctx, attribute, &isJson);
      |                                                                      ^~~~~~~
../../../../ext/panko_serializer/attributes_writer/active_record.c:88:29: note: expected ‘VALUE *’ {aka ‘long unsigned int *’} but argument is of type ‘volatile VALUE *’ {aka ‘volatile long unsigned int *’}
   88 |                      VALUE* isJson) {
      |                      ~~~~~~~^~~~~~
In file included from ../../../../ext/panko_serializer/attributes_writer/active_record.h:9,
                 from ../../../../ext/panko_serializer/attributes_writer/active_record.c:1:
```

* Fixing some benchmarks

* Benchmarks: handle deprecations

Currently active support deprecations are being redirected to STDOUT which fails json parsing of output results.

Instead, we will redirect it to STDERR.

* Rakefile: add namespace for benchmarks

* Linter fixes

* Lint

- Remove `clang-format` check on lint-ruby
- Update clang-format-action: https://github.com/jidicula/clang-format-action/releases/tag/v4.11.0
- Fix linting error (from previous commit)

* Remove EOL versions from CI
  • Loading branch information
yosiat committed Jun 10, 2023
1 parent c5d8c77 commit 9972ccc
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 81 deletions.
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

0 comments on commit 9972ccc

Please sign in to comment.