Skip to content

Commit f802e2e

Browse files
authored
Merge pull request #4316 from rmosolgo/field-type-calls
Performance: reduce a duplicate call to Field#type
2 parents 533fe36 + 7e18089 commit f802e2e

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

benchmark/run.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def self.profile_large_introspection
8080
100.times do |n|
8181
obj_t = Class.new(GraphQL::Schema::Object) do
8282
graphql_name("Object#{n}")
83-
5.times do |n2|
83+
20.times do |n2|
8484
field :"field#{n2}", String do
8585
argument :arg, String
8686
end

lib/graphql/execution/interpreter/runtime.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ def evaluate_selection(path, result_name, field_ast_nodes_or_ast_node, scoped_co
400400
raise "Invariant: no field for #{owner_type}.#{field_name}"
401401
end
402402
end
403+
403404
return_type = field_defn.type
404405

405406
next_path = path.dup
@@ -425,18 +426,17 @@ def evaluate_selection(path, result_name, field_ast_nodes_or_ast_node, scoped_co
425426
total_args_count = field_defn.arguments(context).size
426427
if total_args_count == 0
427428
resolved_arguments = GraphQL::Execution::Interpreter::Arguments::EMPTY
428-
evaluate_selection_with_args(resolved_arguments, field_defn, next_path, ast_node, field_ast_nodes, scoped_context, owner_type, object, is_eager_field, result_name, selections_result, parent_object)
429+
evaluate_selection_with_args(resolved_arguments, field_defn, next_path, ast_node, field_ast_nodes, scoped_context, owner_type, object, is_eager_field, result_name, selections_result, parent_object, return_type)
429430
else
430431
# TODO remove all arguments(...) usages?
431432
@query.arguments_cache.dataload_for(ast_node, field_defn, object) do |resolved_arguments|
432-
evaluate_selection_with_args(resolved_arguments, field_defn, next_path, ast_node, field_ast_nodes, scoped_context, owner_type, object, is_eager_field, result_name, selections_result, parent_object)
433+
evaluate_selection_with_args(resolved_arguments, field_defn, next_path, ast_node, field_ast_nodes, scoped_context, owner_type, object, is_eager_field, result_name, selections_result, parent_object, return_type)
433434
end
434435
end
435436
end
436437

437-
def evaluate_selection_with_args(arguments, field_defn, next_path, ast_node, field_ast_nodes, scoped_context, owner_type, object, is_eager_field, result_name, selection_result, parent_object) # rubocop:disable Metrics/ParameterLists
438+
def evaluate_selection_with_args(arguments, field_defn, next_path, ast_node, field_ast_nodes, scoped_context, owner_type, object, is_eager_field, result_name, selection_result, parent_object, return_type) # rubocop:disable Metrics/ParameterLists
438439
context.scoped_context = scoped_context
439-
return_type = field_defn.type
440440
after_lazy(arguments, owner: owner_type, field: field_defn, path: next_path, ast_node: ast_node, scoped_context: context.scoped_context, owner_object: object, arguments: arguments, result_name: result_name, result: selection_result) do |resolved_arguments|
441441
if resolved_arguments.is_a?(GraphQL::ExecutionError) || resolved_arguments.is_a?(GraphQL::UnauthorizedError)
442442
continue_value(next_path, resolved_arguments, owner_type, field_defn, return_type.non_null?, ast_node, result_name, selection_result)

lib/graphql/tracing/platform_tracing.rb

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def trace(key, data)
3636
trace_field = true # implemented with instrumenter
3737
else
3838
field = data[:field]
39+
# HERE
3940
return_type = field.type.unwrap
4041
trace_field = if return_type.kind.scalar? || return_type.kind.enum?
4142
(field.trace.nil? && @trace_scalars) || field.trace

0 commit comments

Comments
 (0)