coerce_input_literal spends extra time on type checks and non-null recursion

Aberta Para iniciantes
#302 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
78/100
Tipo de issue
Refatoração
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
python
Domínio
performance

Direção de pesquisa

Leia src/graphql/utilities/coerce_input_value.py e o benchmark em tests/benchmarks/test_execution_arguments.py. Verifique como coerce_input_literal lida com tipos NonNull e chama os três auxiliares de verificação de tipos; em seguida, faça as alterações propostas e execute os testes e o benchmark relevantes. O trabalho estará concluído quando o comportamento permanecer igual e o benchmark mostrar a melhoria de desempenho relatada.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

coerce_input_literal in src/graphql/utilities/coerce_input_value.py runs for every literal argument in a query. For example, it runs for multiplier: 2 once per item in tests/benchmarks/test_execution_arguments.py.

The function does two kinds of extra work:

  • For a NonNull type, it calls itself again with the inner type. The second call checks for a variable node and a non-null type again.
  • It uses the is_non_null_type, is_list_type and is_input_object_type helper functions. Each helper is one more function call around an isinstance check.

Measured on Python 3.12, median of 3 runs (time per call):

Situation Now With direct checks Change
Int! literal (multiplier: 2) 734 ns 479 ns 35% faster
[Int!] list of 10 ints 7557 ns 5089 ns 33% faster
input object {a: 1, b: "x"} 2355 ns 1717 ns 27% faster
variable $v 172 ns 156 ns no real change
execute_sync of the 1000-item benchmark query 5.32 ms 5.00 ms 6% faster

Proposed fix: unwrap the NonNull type in place instead of calling the function again. Use direct isinstance checks against GraphQLNonNull, GraphQLList and GraphQLInputObjectType in this one function. The results stay the same, and the full test suite passes with the change.

Environment: graphql-core main at 0aaea71, CPython 3.12.13, Linux x86_64.

Linguagem predominante
Python
Estrelas
534
Forks
159
Merge médio
1d 10h
PRs com merge (30d)
11

Preparar o ambiente

  • Sem Dockerfile nem arquivo Docker Compose
  • Tem um modelo de pull request
  • Sem guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de graphql-python/graphql-core

Todas as issues de graphql-python/graphql-core

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.