Skip to content

Conversation

@rly
Copy link
Contributor

@rly rly commented Aug 13, 2025

Motivation

Fix #1958. Closes #2075. Similar approach as in #2075. Adds a copy argument to get_type_map that is default True but can be set to False. The False setting is used when creating a setter for each attribute in each NWB container class. Previously, a deepcopy was performed when creating every setter, which significantly hurt performance.

This PR deprecates calling get_type_map with any 'extensions' arguments, a use case I have never seen. IMO it's easy for the rare user to just call load_namespaces on the type map than us maintain all this extra convenience logic that even we don't use. See similar PR for hdmf-common in hdmf-dev/hdmf#1302.

It is possible that deepcopying of typemaps in get_type_map can be removed entirely. That will be investigated separately as part of #2120.

How to test the behavior?

Profile performance, run pytest

Checklist

  • Did you update CHANGELOG.md with your changes?
  • Have you checked our Contributing document?
  • Have you ensured the PR clearly describes the problem and the solution?
  • Is your contribution compliant with our coding style? This can be checked running ruff check . && codespell from the source directory.
  • Have you checked to ensure that there aren't other open Pull Requests for the same change?
  • Have you included the relevant issue number using "Fix #XXX" notation where XXX is the issue number? By including "Fix #XXX" you allow GitHub to close issue #XXX when the PR is merged.

@codecov
Copy link

codecov bot commented Aug 13, 2025

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.19%. Comparing base (f9cd2a2) to head (a6bf5bf).
⚠️ Report is 11 commits behind head on dev.

Files with missing lines Patch % Lines
src/pynwb/__init__.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2121      +/-   ##
==========================================
- Coverage   95.32%   95.19%   -0.14%     
==========================================
  Files          28       28              
  Lines        2846     2849       +3     
  Branches      735      736       +1     
==========================================
- Hits         2713     2712       -1     
- Misses         77       83       +6     
+ Partials       56       54       -2     
Flag Coverage Δ
integration 74.16% <63.63%> (-0.12%) ⬇️
unit 85.08% <81.81%> (-0.13%) ⬇️

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.

@rly rly requested a review from Copilot August 13, 2025 01:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Optimizes performance by reducing unnecessary deep copying of type maps when creating NWB container setters. The PR adds a copy parameter to get_type_map() (defaulting to True for backward compatibility) and deprecates the extensions argument in favor of calling load_namespaces() directly on the returned TypeMap.

  • Add copy parameter to get_type_map() to control whether a deep copy is returned
  • Deprecate the extensions argument in get_type_map() with a warning message
  • Update all test files to use the new pattern of calling load_namespaces() on the TypeMap

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/pynwb/init.py Adds copy parameter to get_type_map(), deprecates extensions argument, and updates utility functions to use global TypeMap directly
src/pynwb/core.py Updates _get_type_map() to use copy=False for performance optimization
tests/unit/test_extension.py Refactors test calls to use new pattern of get_type_map() followed by load_namespaces()
tests/integration/helpers/utils.py Updates test helper to use new TypeMap loading pattern
CHANGELOG.md Documents the performance fix, API changes, and deprecation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@rly rly requested a review from stephprince August 13, 2025 01:07
Copy link
Contributor

@stephprince stephprince left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rly rly merged commit 9e06719 into dev Aug 13, 2025
25 of 26 checks passed
@rly rly deleted the fix_get_type_map branch August 13, 2025 16:41
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

4 participants