Skip to content

Optimize log buffer tail reads#24

Open
chinchampu2021-wq wants to merge 1 commit into
Dragoon4002:mainfrom
chinchampu2021-wq:fix/log-buffer-tail-performance
Open

Optimize log buffer tail reads#24
chinchampu2021-wq wants to merge 1 commit into
Dragoon4002:mainfrom
chinchampu2021-wq:fix/log-buffer-tail-performance

Conversation

@chinchampu2021-wq

Copy link
Copy Markdown

Summary

Optimizes tail reads from the in-memory log buffer by avoiding a full deque-to-list copy when the caller requests a small recent window.

Why

GET /logs uses get_logs(). The log buffer can hold up to 2000 entries, but callers often only need a smaller recent window. The previous implementation copied the full deque before slicing. This change reads from the right side of the deque and only materializes the requested tail window.

Benchmark

Local microbenchmark using a 2000-entry deque and requesting the last 50 entries:

old=0.618221s
new=0.107021s
improvement=5.78x

Testing

  • Added tests/test_log_buffer.py.
  • Verified tail order is preserved.
  • Verified limit=0 keeps the existing "return all logs" behavior.
  • Ran manual behavior check because pytest was not installed in my local environment.

References #2.

@vercel

vercel Bot commented Jul 5, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the dragoon4002's projects Team on Vercel.

A member of the Team first needs to authorize it.

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