Repository navigation
[Python] Cache opcode dispatch tables in trivial_inference and atomic types in SchemaTranslation - #41061
Draft
damccorm wants to merge 1 commit into
Draft
[Python] Cache opcode dispatch tables in trivial_inference and atomic types in SchemaTranslation#41061damccorm wants to merge 1 commit into
damccorm wants to merge 1 commit into
Conversation
… SchemaTranslation
Contributor
Author
|
/gemini review |
Contributor
There was a problem hiding this comment.
📋 Review Summary
This PR introduces two clean, well-targeted performance optimizations for pipeline construction: caching the opcode dispatch tables (_SIMPLE_OPS and _INT_ONE_OPS) at the module level in trivial_inference.py, and fast-pathing primitive atomic types in SchemaTranslation.typing_to_runner_api. Both changes preserve existing semantics while avoiding redundant dictionary reconstructions and costly type introspection.
🔍 General Feedback
- In
trivial_inference.py, hoisting_SIMPLE_OPSand_INT_ONE_OPSout ofinfer_return_type_funceliminates repeated module imports andopcodes.__dict__iterations across recursive inference calls. - In
schemas.py, guarding the earlyPRIMITIVE_TO_ATOMIC_TYPEcheck withtry ... except TypeErrorsafely handles unhashable type representations (such asschema_pb2.Schemainstances) while returning a freshschema_pb2.FieldTypeproto for each call.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
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.
Description
Optimizes bytecode return-type inference and schema type translation during pipeline graph construction:
trivial_inference.infer_return_type_func(sdks/python/apache_beam/typehints/trivial_inference.py):infer_return_type_funcimportedopcodesandintrinsic_one_opsand rebuilt thesimple_opsdictionary ({k.upper(): v for k, v in opcodes.__dict__.items()}) on every call._SIMPLE_OPSand_INT_ONE_OPSto module-level cached tables initialized once on first use.SchemaTranslation.typing_to_runner_api(sdks/python/apache_beam/typehints/schemas.py):PRIMITIVE_TO_ATOMIC_TYPEat the top oftyping_to_runner_apibefore inspecting generic origin/dataclass/NamedTuple metadata (1.26x faster schema field translation).Testing
pytest sdks/python/apache_beam/typehints/trivial_inference_test.py sdks/python/apache_beam/typehints/schemas_test.py.