Skip to content

Improve speed and cancel behaviour #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pd95
Copy link
Contributor

@pd95 pd95 commented Mar 21, 2025

This PR consists of two changes:

  1. OKHTTPClient.extractNextJSON():
    By "consuming" the whitespaces and newlines before and after a JSON token, the parsing speed has been improved a lot for long running responses. Previously each extracted JSON left back some whitespaces which had to be skipped again within the buffer.
    In my tests (with a response consisting of 878 tokens sent from a "fake Ollama server", the reception of the whole response went from 7.9s to 2.3s!

  2. OKHTTPClient.stream():
    The Combine based stream() method did not cancel the data task when the stream was cancelled. This could be observed when an Ollamac user pushed the cancel button, but generation still continued in the background.

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