Skip to content

Enhance get_type_map to support deepcopy option and improve extensions handling #2075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

bendichter
Copy link
Contributor

@bendichter bendichter commented May 7, 2025

Cline-assisted

fix #1958

I have addressed the performance issue in PoseEstimationSeries creation by making two key changes:

  1. Modified pynwb.get_type_map() (in src/pynwb/__init__.py):

    • Added a copy parameter (boolean, defaults to True).
    • If copy=False is passed, this function now returns a direct reference to the TypeMap instead of a deepcopy. This is crucial for performance-sensitive internal calls.
    • Corrected the rtype in the @docval decorator from tuple to TypeMap.
  2. Modified NWBMixin._get_type_map() (in src/pynwb/core.py):

    • This method, which is called by HDMF during object instantiation and attribute setting, now calls pynwb.get_type_map(copy=False).
    • This ensures that the expensive deepcopy operation on the TypeMap is avoided in these frequent, performance-critical operations, directly resolving the slowdown.

These changes prevent the unnecessary and costly duplication of the TypeMap object, particularly when creating complex objects like PoseEstimationSeries with many attributes, thus restoring the expected performance.

@bendichter bendichter requested a review from rly May 7, 2025 19:17
Copy link

codecov bot commented May 7, 2025

Codecov Report

Attention: Patch coverage is 47.05882% with 9 lines in your changes missing coverage. Please review.

Project coverage is 94.86%. Comparing base (f956fbb) to head (1c7f24c).

Files with missing lines Patch % Lines
src/pynwb/__init__.py 43.75% 8 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2075      +/-   ##
==========================================
+ Coverage   94.83%   94.86%   +0.03%     
==========================================
  Files          28       28              
  Lines        2749     2748       -1     
  Branches      708      707       -1     
==========================================
  Hits         2607     2607              
+ Misses         82       81       -1     
  Partials       60       60              
Flag Coverage Δ
integration 74.19% <47.05%> (+0.02%) ⬆️
unit 84.86% <47.05%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

[Bug]: PoseEstimationSeries creation is significantly increasing sleap-io test runtimes
1 participant