Skip to content

chore: Miscellaneous performance and quality improvements#221

Open
toby-coleman wants to merge 12 commits intomainfrom
chore/performance-improvements
Open

chore: Miscellaneous performance and quality improvements#221
toby-coleman wants to merge 12 commits intomainfrom
chore/performance-improvements

Conversation

@toby-coleman
Copy link
Contributor

@toby-coleman toby-coleman commented Mar 1, 2026

Summary

Performance and quality improvements from Claude Opus review.

Changes

Performance Improvements

  • Serialization Optimization (serde_channel.py): Removed redundant Base64 encoding/decoding. ZMQ and RabbitMQ now handle raw binary directly, reducing message size by ~33%.

  • Efficiency in component.py:

  • Moved the _can_step check to trigger an early return, avoiding unnecessary dictionary allocations.

  • Replaced redundant deque copies and while/popleft patterns with simple for loops in event handling.

  • IO Controller Refinement (io_controller.py): * Eliminated redundant deque wrapping and intermediate dict() allocations during buffer updates.

  • Switched to {} literal over dict() for idiomatic speed.

  • Decoration-Time Caching (export_mixin.py): Now caches inspect.signature() during decoration rather than on every instance initialization.

  • Memory Management:

  • state_backend.py: Replaced unbounded @cache with a bounded lru_cache(maxsize=256) to prevent memory leaks in long-running processes.

  • zmq_channel.py: Implemented proper task cleanup using add_done_callback to remove completed tasks from module-level sets.

  • Regex Pre-compilation (entities.py): Compiled entity ID patterns at the module level to avoid re-compiling on every function call.

Code Quality & Simplifications

  • Bug Fixes:

  • export_mixin.py: Fixed an operator precedence bug by changing a bitwise & to a logical and.

  • rabbitmq_channel.py: Excluded asyncio.Lock from pickling to prevent serialization errors.

  • registry.py: Reset _duplicate_aliases per subclass to prevent interference between different registries.

  • Logic Consolidation:

  • event_connector_spec_builder.py: Collapsed a two-method split into a single method to eliminate intermediate allocations.

  • Cleanup:

  • zmq_channel.py: Removed production debug prints and dead references to _push_socket.

  • event_handlers.py: Deleted the unused _get_class_path static method.

  • websocket_io.py: Removed unnecessary f prefixes from static strings.

  • state_backend.py: Removed redundant pass statements.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on a series of performance and quality improvements identified during a code review. The changes aim to enhance the efficiency of core components by optimizing common operations like regular expression matching, argument processing in decorators, and data serialization. Additionally, the PR includes general code cleanup, such as modernizing syntax and removing dead code, contributing to a more robust and maintainable codebase.

Highlights

  • Performance Enhancements: Implemented several optimizations including pre-compiling regular expressions, pre-computing argument names for decorators, and streamlining buffer handling in io_controller.py.
  • Serialization Efficiency: Removed redundant Base64 encoding/decoding from the SerdeChannel's serialization process, relying solely on pickle for byte conversion.
  • Code Modernization & Cleanup: Updated dictionary and set initializations to more concise forms, removed unused static methods, and refined logging calls.
  • Registry Initialization: Added initialization for _duplicate_aliases in ClassRegistry to support future alias management.
Changelog
  • plugboard/component/io_controller.py
    • Optimized event processing by directly iterating over flushed events instead of using an intermediate deque.
    • Refactored set creation for connected inputs/outputs to use more concise set comprehensions.
    • Streamlined IOFieldBuffer initialization, item updates, and flush logic for better efficiency.
  • plugboard/connector/serde_channel.py
    • Removed Base64 encoding and decoding from serialization and deserialization functions, simplifying the process to use only pickle.
    • Removed unused b64decode and b64encode imports.
  • plugboard/events/event_handlers.py
    • Removed the unused _get_class_path static method.
  • plugboard/library/websocket_io.py
    • Updated _logger.info calls to pass messages as keyword arguments instead of using f-strings directly in the message string.
  • plugboard/state/state_backend.py
    • Removed a redundant pass statement in the destroy method.
  • plugboard/utils/entities.py
    • Introduced pre-compiled regular expression objects for ENTITY_ID_REGEX and Entity.Job.id_regex to improve performance of parse and is_job_id methods.
  • plugboard/utils/export_mixin.py
    • Moved the computation of positional argument names in _save_args_wrapper to occur once at decoration time, rather than on every function call.
  • plugboard/utils/registry.py
    • Initialized _duplicate_aliases set in __init_subclass__ for ClassRegistry.
Activity
  • The changes were initiated based on a review by Claude Opus, focusing on performance and quality improvements.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

github-actions bot commented Mar 1, 2026

Benchmark comparison for c698160d (base) vs 48c75eaa (PR)


------------------------------------------------------------------------------------------------------------------ benchmark: 2 tests -----------------------------------------------------------------------------------------------------------------
Name (time in ms)                                                                         Min                 Max                Mean            StdDev              Median               IQR            Outliers     OPS            Rounds  Iterations
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_benchmark_process_run (main/.benchmarks/Linux-CPython-3.12-64bit/0001_base)     451.2125 (1.0)      464.1488 (1.0)      457.0564 (1.0)      4.9883 (1.37)     456.3892 (1.0)      7.2680 (1.44)          2;0  2.1879 (1.0)           5           1
test_benchmark_process_run (pr/.benchmarks/Linux-CPython-3.12-64bit/0001_pr)         457.2928 (1.01)     466.5874 (1.01)     461.0853 (1.01)     3.6335 (1.0)      459.8618 (1.01)     5.0358 (1.0)           2;0  2.1688 (0.99)          5           1
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Legend:
  Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
  OPS: Operations Per Second, computed as 1 / Mean

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a series of valuable performance and quality improvements across the codebase. Key changes include optimizing loops, pre-compiling regular expressions, removing unnecessary Base64 encoding, and moving expensive operations outside of decorated function wrappers. These changes enhance both code readability and execution efficiency.

I've found one area for further improvement in plugboard/utils/export_mixin.py to ensure that positional-only arguments are correctly handled when saving arguments for object reconstruction. Overall, this is a solid set of enhancements.

@codecov
Copy link

codecov bot commented Mar 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…single method, eliminating the intermediate dict allocation and set() wrapping.
…:122

asyncio.Lock is not safely picklable. Added "_send_channel_lock" to the exclusion list in __getstate__.
@github-actions
Copy link

github-actions bot commented Mar 2, 2026

Benchmark comparison for c698160d (base) vs b504b466 (PR)


------------------------------------------------------------------------------------------------------------------ benchmark: 2 tests -----------------------------------------------------------------------------------------------------------------
Name (time in ms)                                                                         Min                 Max                Mean            StdDev              Median               IQR            Outliers     OPS            Rounds  Iterations
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_benchmark_process_run (pr/.benchmarks/Linux-CPython-3.12-64bit/0001_pr)         453.3972 (1.0)      465.1546 (1.0)      457.7222 (1.0)      4.7113 (1.0)      456.8499 (1.0)      6.5485 (1.0)           1;0  2.1847 (1.0)           5           1
test_benchmark_process_run (main/.benchmarks/Linux-CPython-3.12-64bit/0001_base)     454.8071 (1.00)     468.4731 (1.01)     461.2625 (1.01)     5.7050 (1.21)     462.1435 (1.01)     9.6380 (1.47)          2;0  2.1680 (0.99)          5           1
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Legend:
  Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
  OPS: Operations Per Second, computed as 1 / Mean

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