Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request implements font caching to optimize performance when rendering visualizations with many detections on large images. The solution addresses issue #484 by using functools.lru_cache to cache ImageFont objects, preventing repeated expensive font loading operations.
Changes:
- Added two new cached utility functions (
default_fontandtruetype_font) insrc/model_api/visualizer/utils.pyusing@lru_cache(maxsize=5)decorator - Updated all visualizer primitives (BoundingBox, Label, Keypoints, Overlay) to use the new cached font functions instead of directly calling
ImageFont.load_default()orImageFont.truetype() - Reorganized imports in scene files to import
get_label_color_mappingfrommodel_api.visualizer.utilsinstead ofmodel_api.visualizer.scene.utils
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/model_api/visualizer/utils.py | Added default_font and truetype_font cached utility functions with LRU cache |
| src/model_api/visualizer/primitive/bounding_box.py | Updated to use cached default_font function |
| src/model_api/visualizer/primitive/label.py | Updated to use cached default_font and truetype_font functions |
| src/model_api/visualizer/primitive/keypoints.py | Updated to use cached default_font function |
| src/model_api/visualizer/primitive/overlay.py | Updated to use cached default_font function |
| src/model_api/visualizer/scene/detection.py | Updated import path for get_label_color_mapping |
| src/model_api/visualizer/scene/segmentation/instance_segmentation.py | Updated import path for get_label_color_mapping |
Comments suppressed due to low confidence (5)
src/model_api/visualizer/utils.py:8
- The copyright header should appear before the imports. The codebase convention is to have the module docstring first, then the copyright header, and then the imports.
src/model_api/visualizer/utils.py:48 - Missing return type annotation. The function should specify its return type, such as
ImageFont.FreeTypeFontor the appropriate type from PIL. The codebase uses return type annotations for similar functions (e.g.,get_label_color_mappingon line 34 has-> dict[str, str]).
src/model_api/visualizer/utils.py:61 - Missing return type annotation. The function should specify its return type, such as
ImageFont.FreeTypeFontor the appropriate type from PIL. The codebase uses return type annotations for similar functions (e.g.,get_label_color_mappingon line 34 has-> dict[str, str]).
src/model_api/visualizer/utils.py:67 - Missing Returns section in the docstring. The docstring should include a Returns section that describes the return value, similar to the
default_fontfunction above (lines 54-55) which documents "A PIL ImageFont instance with the default font and specified size."
src/model_api/visualizer/utils.py:69 - The new cached font functions
default_fontandtruetype_fontlack test coverage. Since the visualizer module has comprehensive test coverage (see tests/unit/visualizer/test_primitive.py), consider adding tests to verify that the caching mechanism works correctly. The tests should verify that repeated calls with the same parameters return the same cached object, and that different parameters return different objects.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Base automatically changed from
mgumowsk/GETI-480-adjusting-visualization-to-image-size
to
master
February 24, 2026 11:39
6660bdc to
5cdae4e
Compare
mgumowsk
approved these changes
Feb 25, 2026
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.
What does this PR do?
This pull request implements font caching to optimize performance when rendering visualizations with many detections on large images. The solution addresses issue #484 by using functools.lru_cache to cache ImageFont objects, preventing repeated expensive font loading operations.
Fixes #484
Before submitting