Como acompanhar os tamanhos de binários do Python com PyInstaller em CI

Everett Pompeii

Everett Pompeii


Os tamanhos de binários podem aumentar com o tempo, especialmente em Python com PyInstaller. Benchmarking Contínuo é a prática de executar benchmarks em cada conjunto de alterações para garantir que as mudanças não introduzam regressões de desempenho. Você pode tratar os tamanhos de binários como um benchmark e monitorá-los no CI para detectar grandes tamanhos de binários. A maneira mais fácil de implementar Benchmarking Contínuo para tamanhos de binário Python com PyInstaller é usar o Bencher.

O que é o Bencher?

Bencher is a suite of continuous benchmarking tools. Have you ever had a performance regression impact your users? Bencher could have prevented that from happening. Bencher allows you to detect and prevent performance regressions before they make it to production.

  • Run: Run your benchmarks locally or in CI using your favorite benchmarking tools. The bencher CLI simply wraps your existing benchmark harness and stores its results.
  • Track: Track the results of your benchmarks over time. Monitor, query, and graph the results using the Bencher web console based on the source branch, testbed, benchmark, and measure.
  • Catch: Catch performance regressions in CI. Bencher uses state of the art, customizable analytics to detect performance regressions before they make it to production.

For the same reasons that unit tests are run in CI to prevent feature regressions, benchmarks should be run in CI with Bencher to prevent performance regressions. Performance bugs are bugs!

Passos para o Bencher Cloud

  1. Crie uma conta no Bencher Cloud.
  2. Crie um token de API e adicione-o ao seu CI como um segredo.
  3. Crie um fluxo de trabalho para o seu CI, como GitHub Actions ou GitLab CI/CD.
  4. Instale o Bencher CLI no seu fluxo de trabalho CI.
  5. Compile seu código Python com o subcomando bencher run em seu fluxo de trabalho CI usando a opção --file-size definida para o caminho de saída do seu binário juntamente com o adaptador json.

Passos para Bencher Self-Hosted

  1. Crie uma instância Bencher Self-Hosted.
  2. Crie uma conta em sua instância Bencher Self-Hosted.
  3. Crie um token de API e adicione-o ao seu CI como um segredo.
  4. Crie um fluxo de trabalho para o seu CI, como GitHub Actions ou GitLab CI/CD.
  5. Instale o Bencher CLI no fluxo de trabalho do seu CI. Certifique-se de que a versão do CLI corresponda à versão da sua instância Bencher Self-Hosted.
  6. Compile seu código Python com o subcomando bencher run em seu fluxo de trabalho CI usando a opção --file-size definida para o caminho de saída do seu binário juntamente com o adaptador json e configurando a opção --host para a URL de sua instância Bencher Self-Hosted.

⚖️ File Size

The bencher run CLI subcommand can be used to track the file size (ie binary size) of your deliverables with the --file-size option. The --file-size option expects a file path to the file who’s size will be measured. Under the hood, bencher run outputs the results as Bencher Metric Format (BMF) JSON. It is therefore good practice to explicitly use the json adapter. For more details see how to track file size.

The file-size Measure (ie bytes (B)) is gathered. Only the file size value (ie value) is available. Neither lower_value nor upper_value are collected. The file-size Measure is not created by default for all Projects. However, when you use the --file-size option, this Measure will be automatically created for your Project. The --file-size option can be used multiple times to track multiple file sizes.

Terminal window
bencher run --file-size ./binary --adapter json "pyinstaller --onefile binary.py"

Acompanhe seus benchmarks no CI

Alguma vez teve uma regressão de desempenho que afetou seus usuários? O Bencher poderia ter evitado que isso acontecesse com o benchmarking contínuo.

🤖 Este documento foi gerado automaticamente pelo OpenAI GPT-4. Pode não ser preciso e pode conter erros. Se você encontrar algum erro, abra um problema no GitHub.