Open
Conversation
0f3790c to
307a1c6
Compare
Introduces a read optimization pipeline that merges scattered read requests into contiguous blocks and packs them into minimal PDU exchanges, reducing round-trips when reading multiple variables. - snap7/optimizer.py: Pure-logic optimization with sort, merge, packetize, and extract_results functions - snap7/s7protocol.py: build_multi_read_request and extract_multi_read_data methods for multi-item S7 READ_AREA PDUs - snap7/server/__init__.py: Server-side multi-item read support - snap7/client.py: read_multi_vars now uses optimizer for 2+ dict items, with plan caching for repeated layouts - tests/test_optimizer.py: 23 tests covering unit and integration scenarios Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…sues - Fix cache mutation bug: deep-copy cached ReadPackets before assigning buffers so repeated calls don't corrupt cached state - Remove dead _map_area_int method - Replace per-call set comprehension with module-level _VALID_AREA_VALUES frozenset for Area validation - Fix O(n^2) byte concatenation in build_multi_read_request using list and b"".join() - Clear optimizer cache on disconnect - Add use_optimizer attribute (default True) to allow opting out Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add experimental warnings to optimizer module, client docstring, and documentation so users know the API may change. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
307a1c6 to
f10e542
Compare
Fire multiple PDU requests back-to-back on the same TCP connection and collect responses by sequence number, reducing round-trip overhead when reading many scattered variables. - data_available() on ISOTCPConnection: select()-based readable check - _send_receive_parallel(): pipelining multiple S7 requests - _auto_tune_parallel(): set max_parallel based on negotiated PDU size - _execute_packets_parallel/sequential: dispatch strategies - Comprehensive optimizer documentation page Inspired by QuakeString/python-snap7-optimized fork. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The heartbeat thread holds _reconnect_lock while calling get_cpu_state(), which calls _send_receive(). Adding the lock to _send_receive() caused a deadlock with threading.Lock. Switch to RLock (reentrant) so the same thread can acquire the lock multiple times without deadlocking. This also protects _send_receive_parallel() with the lock to prevent conflicts between parallel dispatch and heartbeat probes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
snap7/optimizer.py) that merges scatteredread_multi_vars()requests into contiguous blocks and packs them into minimal PDU-sized S7 exchangesread_multi_vars()with 2+ dict items now automatically optimizes: adjacent reads are merged (configurable gap tolerance viaclient.multi_read_max_gap), and the optimization plan is cached for repeated layoutsTest plan
🤖 Generated with Claude Code