openzim / openzim/python-scraperlib

Is beartype cost acceptable?

Ouverte
#325 4 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

question
Langage dominant
Python
Étoiles
31
Forks
27
Merge moyen
3 j 7 h
PR mergées (30 j)
2

Description

Context

While investigating a memory leak (fixed in #324 — a closure in RxRewriter.rewrite() was being re-decorated by beartype's claw hook on every call, permanently pinning it via beartype's own is_object_blacklisted cache), the fix removed the leak but also raised the question of how much runtime cost beartype_this_package() (used project-wide in zimscraperlib/__init__.py) actually adds. This issue is to share those numbers and discuss whether the tradeoff is the one we want.

Methodology

Ran warc2zim to completion, twice, on the same input, same machine, back to back:

warc2zim --publisher=openZIM --content-header-bytes-length=2048 \
  --zim-file=www.physicsclassroom.com_56e21a6e.zim --name=www.physicsclassroom.com_56e21a6e \
  --scraper-suffix "zimit 3.1.2" --output output \
  --url https://www.physicsclassroom.com/ \
  <local WARC, 731MB compressed, ~14.5K ZIM entries> --overwrite

wrapped in /usr/bin/time -v for wall-clock, CPU, and peak RSS.

  • Run A: zimscraperlib as-is (beartype_this_package() active).
  • Run B: same install, with the single line beartype_this_package() in zimscraperlib/__init__.py commented out (everything else identical), bytecode cache cleared between runs.

Both runs post-date the #324 leak fix, so memory is no longer confounded by that bug.

Results

With beartype (Run A) Without beartype (Run B) Delta
Wall clock time 53:50 (3230s) 44:08 (2648s) −18.0%
User CPU time 3835s 3251s −15.2%
Max RSS 924,060 KB 885,356 KB −4.2% (noise-level)

Both runs completed successfully with an identical entry count. Memory is essentially the same between the two (the small gap is within run-to-run noise).

Takeaway

Runtime type-checking via beartype_this_package() costs roughly 15-18% additional wall-clock/CPU time on this workload, with no meaningful memory cost of its own now that #324 is fixed.

Discussion

Is this tradeoff (broad runtime type-safety across zimscraperlib, for ~15-18% slower conversions) the one we want, or should beartype's coverage be scoped down — e.g. excluding hot paths like zimscraperlib.rewriting from beartype_this_package(), or using a cheaper BeartypeStrategy for those modules — while keeping full checking elsewhere, or allowing to fully disable beartype "on-demand" (e.g. enable it only for unit and e2e tests of scraperlib and scrapers)?

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par zimscraperlib/init.py et l’appel à beartype_this_package(), puis examinez le hot path zimscraperlib.rewriting ainsi que la commande de benchmark warc2zim documentée. Reproduisez les exécutions appariées si nécessaire et comparez le temps réel, le temps CPU et le RSS maximal. Le travail est terminé lorsqu’il est convenu et documenté de limiter ou non la couverture, de la configurer avec une stratégie moins coûteuse ou de la désactiver pour certaines exécutions.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
performance
Type d'issue
Refactorisation
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
Calme
Clarté
À clarifier
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.