Skip to content

Optimize slcan serial read and buffer processing#2080

Open
YeWenxuan64 wants to merge 1 commit into
hardbyte:mainfrom
YeWenxuan64:slcan_read_perf_improve
Open

Optimize slcan serial read and buffer processing#2080
YeWenxuan64 wants to merge 1 commit into
hardbyte:mainfrom
YeWenxuan64:slcan_read_perf_improve

Conversation

@YeWenxuan64

Copy link
Copy Markdown

Refactor reading from serial to improve performance by using C level's bytearray.find() to replace for iteration.

Summary of Changes

Key changes:

  • Removed the Python-level for i, byte in enumerate(buffer): if byte in (ok, err): ... loop
  • Replaced with two buffer.find(byte) calls at C level for terminator detection

Related Issues / Pull Requests

  • None

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Other (please describe):

Checklist

  • I have followed the contribution guide.
  • I have added or updated tests as appropriate.
  • I have added or updated documentation as appropriate.
  • I have added a news fragment for towncrier.
  • All checks and tests pass (tox).

Additional Notes

Method vs bytearray.find (v5)
v1 for loop ~2–4× slower
v2 single-pass local ~2–4× slower
v3 filter+next ~3–6× slower
v4 bytes.find ~1.5–2× slower (copy overhead)
v5 bytearray.find 1.0× (baseline)

I could also provide performance testing scripts (generate by AI) if you need.

Refactor reading from serial to improve performance by using C level's bytearray.find() to replace `for` iteration.
@mergify

mergify Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@YeWenxuan64

Copy link
Copy Markdown
Author

A benchmark generate by AI
benchmark_read_methods.py

@YeWenxuan64

Copy link
Copy Markdown
Author

@Mergifyio queue

@mergify

mergify Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

queue

☑️ Command disallowed due to command restrictions in the Mergify configuration.

Details
  • sender-permission >= write

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