Skip to content

Avoid inspect.stack() in tensorflow_graphics.util.export_api. - #5407

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_1031069757
Nov 27, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_1031069757

Conversation

@copybara-service

Copy link
Copy Markdown

Avoid inspect.stack() in tensorflow_graphics.util.export_api.

Calling inspect.stack()[1] at module import time in get_functions_and_classes() and get_modules() inspects every outer frame on the call stack and triggers inspect.getmodule() scans across all entries in sys.modules for uncached import frames. In large Python applications with deep import stacks and thousands of loaded modules, this makes importing a handful of tensorflow_graphics modules take several seconds.

Read the immediate caller frame directly via sys._getframe(2) and resolve its module in O(1) from sys.modules when module.__dict__ is frame.f_globals, falling back to inspect.getmodule(frame) otherwise.

@copybara-service
copybara-service Bot force-pushed the test_1031069757 branch 6 times, most recently from a9168cd to 35e2164 Compare November 27, 2026 14:38
Calling `inspect.stack()[1]` at module import time in `get_functions_and_classes()` and `get_modules()` inspects every outer frame on the call stack and triggers `inspect.getmodule()` scans across all entries in `sys.modules` for uncached import frames. In large Python applications with deep import stacks and thousands of loaded modules, this makes importing a handful of `tensorflow_graphics` modules take several seconds.

Read the immediate caller frame directly via `sys._getframe(2)` and resolve its module in O(1) from `sys.modules` when `module.__dict__ is frame.f_globals`, falling back to `inspect.getmodule(frame)` otherwise.

PiperOrigin-RevId: 1031264643
@copybara-service
copybara-service Bot merged commit 58737b7 into master Nov 27, 2026
5 checks passed
@copybara-service
copybara-service Bot deleted the test_1031069757 branch November 27, 2026 15:33
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