Skip to content
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

heavy Processor called multiple times #1915

Open
planetis-m opened this issue Sep 21, 2024 · 4 comments
Open

heavy Processor called multiple times #1915

planetis-m opened this issue Sep 21, 2024 · 4 comments

Comments

@planetis-m
Copy link

Hi,

I've developed a prompt that performs spellchecking by integrating the pyspellcheck library. However, I've noticed that underlining misspelled words causes a significant lag. I've optimized the spell-checking process by using caches, but the lag persists.

Upon further investigation, I added a print statement to the apply_transformation function and found that it is being called four times per keystroke. I attempted to create a ConditionalProcessor to address this, but there is no key_inserted event. Instead, I implemented hashing the buffer's text, but this approach breaks the underlining functionality entirely.

Any advice on how to resolve this issue would be greatly appreciated.

Thank you!

Sample: https://gist.github.com/planetis-m/ad078e0e184439e2712f3b853c192d01

@planetis-m
Copy link
Author

I tried creating an async Filter, this didn't work:

venv/lib/python3.12/site-packages/prompt_toolkit/completion/base.py:346: RuntimeWarning: coroutine 'AsyncSleepFilter.__call__' was never awaited
  if self.filter():
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

@planetis-m

This comment was marked as outdated.

@planetis-m

This comment was marked as outdated.

@nitanmarcel
Copy link

I hit the missing async pre-processor thing too when wanting to implement a hover for a language server integration in my code. @jonathanslenders An async Processor would be handy. Until then, running the spell checker asynchronous and calling in from a non async code is a viable solution. asyncer can handle this easily by automatically running the async code on another thread.

https://asyncer.tiangolo.com/tutorial/asyncify/
https://asyncer.tiangolo.com/tutorial/syncify/#run-async-code-from-blocking-code

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

No branches or pull requests

2 participants