Skip to content

Hoist conditional call results into locals to reduce repeated evaluations#9

Merged
pixge merged 1 commit intocodex/modify-scaffolding-and-implement-loggingfrom
codex/refactor-json-unit-calls-for-bps-1.0
Jan 11, 2026
Merged

Hoist conditional call results into locals to reduce repeated evaluations#9
pixge merged 1 commit intocodex/modify-scaffolding-and-implement-loggingfrom
codex/refactor-json-unit-calls-for-bps-1.0

Conversation

@pixge
Copy link
Owner

@pixge pixge commented Jan 11, 2026

Motivation

  • Reduce repeated function or attribute call evaluations inside if conditions to lower overhead in low-BPS hotspots.
  • Make intent explicit by assigning condition results to local variables and reuse them in subsequent checks.
  • Keep existing logic and behavior unchanged while improving readability.

Description

  • Cache filename.endswith(".py") into is_python_file in directory/scanner.py and file/path_collector.py to avoid repeated calls.
  • Hoist context checks in function/symbol_collector.py by storing _is_load_context, _is_store_or_del_context, _is_declared_nonlocal_or_global, and _is_self_attribute_read into local variables and reuse them.
  • Simplify module/symbol_collector.py ExceptHandler and _extract_target_names checks by caching handler_name and is_name locally.
  • Reuse class_method_names and is_self_call in indirection/analyzer.py to avoid repeated lookups and string checks.

Testing

  • Ran pytest -q in the repository root to exercise the test suite.
  • Test run failed during collection with ModuleNotFoundError: No module named 'codra', so tests could not be executed to completion.

Codex Task

@pixge pixge merged commit 63c72bd into codex/modify-scaffolding-and-implement-logging Jan 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant