Remove the debug timing loop from Annot.update() - #5087
Open
brokkoli71 wants to merge 1 commit into
Open
Conversation
Annot.update() unconditionally calls Annot.update_timing_test(), a static method that counts to 30,000 in pure Python and returns a sum the caller discards. It costs about 0.68 ms per annotation. The method is undocumented and had no other callers, so it is removed along with the call.
Contributor
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
Author
|
I have read the CLA Document and I hereby sign the CLA |
Author
|
recheck |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Annot.update()unconditionally callsAnnot.update_timing_test(), a static method that counts to 30,000 in pure Python and returns a sum the caller discards:It looks like a benchmark that was committed by accident. It is present in every release from 1.23.0 through 1.28.2 and in current
main, and absent from 1.22.x, so it appears to have come in with thesrc/__init__.pyrewrite.Cost
Measured with PyMuPDF 1.27.2.3 on Python 3.14:
Annot.update()call.doc.save()for the same file is 86 ms — so the accidental loop costs more than saving the document.Because it is pure Python it also holds the GIL, so it cannot be hidden on a worker thread. In an interactive application that writes annotations on the UI thread it is a visible freeze.
The change
The method is undocumented and had no other callers anywhere in the repository (the only two references were the call and the definition), so this removes both. Happy to trim it to just the call site if you would rather keep the method around.
I checked that a document written with the call removed is byte-identical to one written with it, apart from the trailer's random
/ID, which differs between any two saves of the same document anyway.