Using a paged cache to speed up event streams
- [ ] This change is worth documenting at https://docs.all-hands.dev/
- [x] Include this change in the Release Notes. If checked, you must provide an end-user friendly description for your change below
End-user friendly description of the problem this fixes or functionality that this introduces.
This PR improves the performance of event retrieval in OpenHands, particularly for conversations with a large number of events. Users should experience faster loading times when viewing long conversations.
Give a summary of what the PR does, explaining any non-trivial design decisions.
This PR deliberately does includes only additive changes to the file structure. It introduces a set of json files where each contains 25 events as a cache.
Key changes include:
- Added a
_CachePageclass to store and retrieve batches of events efficiently - Implemented cache page creation when adding events to the event stream
- Modified the event retrieval logic to use cache pages when available
- Added comprehensive unit tests to verify cache functionality and performance
The implementation uses a configurable cache size (default: 25 events per page) and automatically creates cache pages as events are added. This approach significantly reduces the number of file operations needed when retrieving events from long conversations, improving performance without requiring changes to the existing API. For example, if you are using network attached storage where each file read can take ~20ms, this means that reading an event stream with 500 events goes from taking ~10 seconds down to ~400ms.
Link of any specific issues this addresses.
No specific issue linked.
To run this PR locally, use the following command:
docker run -it --rm -p 3000:3000 -v /var/run/docker.sock:/var/run/docker.sock --add-host host.docker.internal:host-gateway -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:70b6a66-nikolaik --name openhands-app-70b6a66 docker.all-hands.dev/all-hands-ai/openhands:70b6a66