Skip to content

Expressions Performance Improvements - #199

Merged
ccrisan merged 15 commits into
mainfrom
improvements/expressions-performance
Apr 18, 2026
Merged

Expressions Performance Improvements#199
ccrisan merged 15 commits into
mainfrom
improvements/expressions-performance

Conversation

@ccrisan

@ccrisan ccrisan commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR focuses on reducing overhead in expression evaluation and core update paths by avoiding repeated allocations, adding caching, and improving queue data structures across ports/sessions/peripherals/slaves.

Changes:

  • Replace many dict(...) copies with .copy(), and switch get_all() registries to return ValuesView for lower allocation overhead.
  • Optimize expression/port runtime behavior via caching (e.g., port lookup cache, filtered attrdefs caches) and using deque for event/value queues.
  • Add/adjust tests for new caching/debouncing behavior and session queue semantics.

Reviewed changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tests/unit/qtoggleserver/peripherals/api/test_funcs.py Use .copy() when building payloads to avoid extra conversions.
tests/unit/qtoggleserver/mock/peripherals.py Avoid extra dict() conversion for kwargs copying.
tests/unit/qtoggleserver/core/test_sessions.py New unit tests for Session queue/de-duplication behavior and deque usage.
tests/unit/qtoggleserver/core/test_ports.py Update tests for EvalContext construction and new debounced attr-change behavior; add to_json cache tests.
tests/unit/qtoggleserver/core/test_main.py Update tests to match handle_value_changes(all_ports, ...) signature and port iteration change.
tests/unit/qtoggleserver/core/expressions/test_various.py Adjust expectations to numeric 0/1 behavior for certain expression functions.
tests/unit/qtoggleserver/core/expressions/test_port.py Add tests for port lookup caching and invalidation on port removal.
tests/unit/qtoggleserver/core/expressions/test_literal.py Update literal eval tests to reflect boolean coercion to 0/1.
tests/unit/qtoggleserver/core/device/test_attrs.py Large refactor/expansion of tests for device attrs caching, schema building, and filtered attrdefs caching.
tests/integration/expressions/test_misc.py Adjust ordering around expression setup/value initialization for timing-sensitive behavior.
qtoggleserver/web/base.py Avoid extra dict() conversion when handling API call exception kwargs.
qtoggleserver/utils/debounced.py Rename debouncer utility and adjust argument aggregation behavior.
qtoggleserver/slaves/ports.py Avoid repeated dict allocations for attrdefs; copy cached attrs more efficiently.
qtoggleserver/slaves/devices.py Return copies of cached attrs in JSON/save paths; get_all() returns ValuesView.
qtoggleserver/slaves/api/funcs/devices.py Use snapshot iteration for removals; avoid extra dict() conversions; schema copy.
qtoggleserver/peripherals/peripheral.py Avoid extra dict() conversion when supplying peripheral arg to ports.
qtoggleserver/peripherals/api/funcs.py Use snapshot iteration for peripheral removals during restore.
qtoggleserver/peripherals/init.py get_all() now returns ValuesView; reduce allocations in params copying/persisting.
qtoggleserver/lib/polled.py Avoid extra dict() conversion for attrdef cloning.
qtoggleserver/lib/filtereventhandler.py Add TODO markers for attribute evaluation in expression contexts.
qtoggleserver/drivers/persist/redis.py Avoid extra dict() conversions for record/filter copies.
qtoggleserver/drivers/persist/mongo.py Avoid extra dict() conversions for record/filter copies.
qtoggleserver/drivers/persist/json.py Optimize ID generation by caching per-collection max IDs; avoid extra dict() conversions.
qtoggleserver/core/sessions.py Switch session event queue to deque; simplify de-duplication; minor timestamp handling change.
qtoggleserver/core/ports.py Add caches, debounced post-set_attr work, ValuesView get_all, port removed state, and various expression/context changes.
qtoggleserver/core/main.py Avoid repeated get_all() allocations by snapshotting ports once per update.
qtoggleserver/core/history.py Use snapshot iteration over ports to avoid live view mutation issues.
qtoggleserver/core/expressions/various.py Return numeric 0/1 in some functions; attempt to reduce boolean usage.
qtoggleserver/core/expressions/timeprocessing.py Use deque for history/queues; cast widths to int.
qtoggleserver/core/expressions/ports.py Add cached port lookup with invalidation on port removal; faster whitespace stripping.
qtoggleserver/core/expressions/literalvalues.py Pre-coerce boolean literals to 0/1; simplify eval.
qtoggleserver/core/expressions/functions.py Cache child function args list for faster dependency scans.
qtoggleserver/core/expressions/base.py Change EvalContext defaults/fields and narrow EvalResult typing.
qtoggleserver/core/expressions/init.py Faster whitespace stripping in parse entrypoint.
qtoggleserver/core/device/attrs.py Add caching for attrdefs/attrs/to_json filtered defs and invalidation helpers.
qtoggleserver/core/api/funcs/various.py Catch listen cancellation.
qtoggleserver/core/api/funcs/ports.py Use snapshot iteration and schema copy during port restore.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread qtoggleserver/core/expressions/timeprocessing.py
Comment thread qtoggleserver/core/api/funcs/various.py
Comment thread tests/unit/qtoggleserver/core/test_ports.py
Comment thread qtoggleserver/core/ports.py
Comment thread qtoggleserver/core/ports.py
Comment thread qtoggleserver/core/ports.py
Comment thread qtoggleserver/core/expressions/timeprocessing.py
Comment thread qtoggleserver/core/expressions/base.py
Comment thread qtoggleserver/core/expressions/various.py Outdated
@ccrisan
ccrisan force-pushed the improvements/expressions-performance branch from 3530b14 to 64e201d Compare April 15, 2026 20:51
@ccrisan
ccrisan requested a review from Copilot April 15, 2026 20:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread qtoggleserver/core/expressions/timeprocessing.py
Comment thread qtoggleserver/core/expressions/timeprocessing.py
Comment thread tests/unit/qtoggleserver/core/device/test_attrs.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread qtoggleserver/core/expressions/literalvalues.py Outdated
@ccrisan
ccrisan merged commit 76155b2 into main Apr 18, 2026
7 checks passed
@ccrisan
ccrisan deleted the improvements/expressions-performance branch April 18, 2026 11:26
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.

2 participants