Skip to content

Improved performance of image_upload() in server.py#12991

Open
V1sionVerse wants to merge 1 commit intoComfy-Org:masterfrom
V1sionVerse:image-upload-file-size-check
Open

Improved performance of image_upload() in server.py#12991
V1sionVerse wants to merge 1 commit intoComfy-Org:masterfrom
V1sionVerse:image-upload-file-size-check

Conversation

@V1sionVerse
Copy link

@V1sionVerse V1sionVerse commented Mar 16, 2026

Added a cheap file size comparison before the expensive file hash comparison.
This should considerably improve worst-case performance.

See issue: #12965

Added a cheap file size comparison before the expensive file hash comparison.
This should considerably improve average-case performance.
@coderabbitai
Copy link

coderabbitai bot commented Mar 16, 2026

📝 Walkthrough

Walkthrough

The image_upload function in server.py has been modified to optimize duplicate file detection when overwriting is not requested. The uploaded file size is now computed once upfront by seeking to the end and resetting the file position. In the collision detection loop, a size check is performed before hash comparison; hashing only occurs when the existing file size matches the uploaded file size. This introduces an early size-based guard to skip unnecessary hash computations for different-sized files. The overall control flow remains unchanged with the addition of the preliminary size calculation and conditional hash comparison.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: a performance improvement to the image_upload() function by adding an early size check before expensive hash comparison.
Description check ✅ Passed The pull request description clearly relates to the changeset, explaining the optimization of adding a file size comparison before hash comparison in image_upload().

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use TruffleHog to scan for secrets in your code with verification capabilities.

Add a TruffleHog config file (e.g. trufflehog-config.yml, trufflehog.yml) to your project to customize detectors and scanning behavior. The tool runs only when a config file is present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant