Skip to content

Commit 5afb3b5

Browse files
authored
Merge pull request #4899 from rmosolgo/ast-strings
Reduce duplicated identifier strings in C parser
2 parents 1e662f4 + df03c36 commit 5afb3b5

File tree

19 files changed

+230
-131
lines changed

19 files changed

+230
-131
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ jobs:
4444
include:
4545
- gemfile: Gemfile
4646
ruby: 3.2
47-
# Rails 6.1 is tested with Postgresql below
4847
- gemfile: gemfiles/rails_7.0.gemfile
4948
ruby: 3.1
5049
- gemfile: gemfiles/rails_master.gemfile
@@ -93,14 +92,14 @@ jobs:
9392
--health-timeout 5s
9493
--health-retries 5
9594
steps:
96-
- run: echo BUNDLE_GEMFILE='gemfiles/rails_6.1_postgresql.gemfile' > $GITHUB_ENV
95+
- run: echo BUNDLE_GEMFILE='gemfiles/rails_7.1_postgresql.gemfile' > $GITHUB_ENV
9796
- run: echo DATABASE='POSTGRESQL' > $GITHUB_ENV
9897
- run: echo PGPASSWORD='postgres' > $GITHUB_ENV
9998
- run: echo GRAPHQL_CPARSER=1 > $GITHUB_ENV
10099
- uses: actions/checkout@v4
101100
- uses: ruby/setup-ruby@v1
102101
with:
103-
ruby-version: 2.7
102+
ruby-version: "3.3"
104103
bundler-cache: true
105104
- run: bundle exec rake compile test
106105
mongodb_test:

Rakefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ namespace :bench do
124124
GraphQLBenchmark.profile_to_definition
125125
end
126126

127+
desc "Load schema from SDL"
128+
task :profile_from_definition do
129+
prepare_benchmark
130+
GraphQLBenchmark.profile_from_definition
131+
end
132+
127133
desc "Compare GraphQL-Batch and GraphQL-Dataloader"
128134
task :profile_batch_loaders do
129135
prepare_benchmark

benchmark/run.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,26 @@ def self.profile_to_definition
487487
report.pretty_print
488488
end
489489

490+
def self.profile_from_definition
491+
# require "graphql/c_parser"
492+
schema_str = SILLY_LARGE_SCHEMA.to_definition
493+
494+
Benchmark.ips do |x|
495+
x.report("from_definition") { GraphQL::Schema.from_definition(schema_str) }
496+
end
497+
498+
result = StackProf.run(mode: :wall, interval: 1) do
499+
GraphQL::Schema.from_definition(schema_str)
500+
end
501+
StackProf::Report.new(result).print_text
502+
503+
report = MemoryProfiler.report do
504+
GraphQL::Schema.from_definition(schema_str)
505+
end
506+
507+
report.pretty_print
508+
end
509+
490510
def self.profile_batch_loaders
491511
require_relative "./batch_loading"
492512
include BatchLoading

gemfiles/rails_6.1.gemfile

Lines changed: 0 additions & 18 deletions
This file was deleted.

gemfiles/rails_6.1_postgresql.gemfile renamed to gemfiles/rails_7.1_postgresql.gemfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ gem "bootsnap"
66
gem "ruby-prof", platform: :ruby
77
gem "pry"
88
gem "pry-stack_explorer", platform: :ruby
9-
gem "rails", "~> 6.1.0", require: "rails/all"
9+
gem "rails", "~> 7.1.0", require: "rails/all"
1010
gem "pg", platform: :ruby
1111
gem "sequel"
12+
gem "evt"
13+
gem "async"
14+
gem "libev_scheduler"
1215

1316
gemspec path: "../"

graphql-c_parser/ext/graphql_c_parser_ext/graphql_c_parser_ext.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "graphql_c_parser_ext.h"
22

3-
VALUE GraphQL_CParser_Lexer_tokenize_with_c(VALUE self, VALUE query_string) {
4-
return tokenize(query_string);
3+
VALUE GraphQL_CParser_Lexer_tokenize_with_c_internal(VALUE self, VALUE query_string, VALUE fstring_identifiers) {
4+
return tokenize(query_string, RTEST(fstring_identifiers));
55
}
66

77
VALUE GraphQL_CParser_Parser_c_parse(VALUE self) {
@@ -13,7 +13,7 @@ void Init_graphql_c_parser_ext() {
1313
VALUE GraphQL = rb_define_module("GraphQL");
1414
VALUE CParser = rb_define_module_under(GraphQL, "CParser");
1515
VALUE Lexer = rb_define_module_under(CParser, "Lexer");
16-
rb_define_singleton_method(Lexer, "tokenize_with_c", GraphQL_CParser_Lexer_tokenize_with_c, 1);
16+
rb_define_singleton_method(Lexer, "tokenize_with_c_internal", GraphQL_CParser_Lexer_tokenize_with_c_internal, 2);
1717
setup_static_token_variables();
1818

1919
VALUE Parser = rb_define_class_under(CParser, "Parser", rb_cObject);

graphql-c_parser/ext/graphql_c_parser_ext/graphql_c_parser_ext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef Graphql_ext_h
22
#define Graphql_ext_h
33
#include <ruby.h>
4+
#include <ruby/encoding.h>
45
#include "lexer.h"
56
#include "parser.h"
67
void Init_graphql_c_parser_ext();

0 commit comments

Comments
 (0)