Skip to content

perf(codec): improve performance by storing next index - #870

Merged
robjtede merged 3 commits into
actix:mainfrom
JohnTitor:line-codec-next-index
Aug 27, 2026
Merged

perf(codec): improve performance by storing next index#870
robjtede merged 3 commits into
actix:mainfrom
JohnTitor:line-codec-next-index

Conversation

@JohnTitor

@JohnTitor JohnTitor commented Apr 30, 2026

Copy link
Copy Markdown
Member

PR Type

perf

PR Checklist

Check your PR fulfills the following:

  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • A changelog entry has been made for the appropriate packages.
  • Format code with the latest stable rustfmt

Overview

Improve performance from O(n^2) to O(n) by storing next_index in LinesCodec. The idea is from https://docs.rs/tokio-util/latest/src/tokio_util/codec/lines_codec.rs.html.
Didn't touch the changelog as it's unreleased yet.

@robjtede

Copy link
Copy Markdown
Member

thoughts on a .reset() method, in case someone legit wants to use the same struct for a new buffer ?

@JohnTitor
JohnTitor force-pushed the line-codec-next-index branch from 42b0f8f to d26ccb6 Compare May 7, 2026 10:50
@JohnTitor

Copy link
Copy Markdown
Member Author

After some thinking of this, it'd be a bit tricky to support such a usecase as it might cause index corruption. In d26ccb6, I tightened its availability for external use for now. Maybe we could revisit this topic if someone wants to use it.

@robjtede
robjtede enabled auto-merge August 27, 2026 20:11
@robjtede
robjtede added this pull request to the merge queue Aug 27, 2026
Merged via the queue into actix:main with commit 29ca22b Aug 27, 2026
15 checks passed
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