prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.29k stars 715 forks source link

Performance tips? #1425

Open davidbrochart opened 3 years ago

davidbrochart commented 3 years ago

Thanks for this great library. I am using it in https://github.com/davidbrochart/nbterm, a Jupyter Notebook in the terminal. So far it works great, but I'm not sure I'm using prompt-toolkit right, and maybe I am abusing its flexibility at the cost of a loss in performance. In nbterm, the complexity of the layout is directly linked to the number of cells in the notebook, and I have seen that it doesn't scale very well. I would have thought that cells not visible on the screen would not matter (because not rendered), but it looks like it does, e.g. if I have 100 cells but only 10 fit on the screen, then it's "as slow as" rendering these 100 cells. Even focusing on a cell gets slow (using up and down arrows), even if the layout doesn't have to be re-rendered. Maybe I am doing something wrong, or my application is not well structured. So I was wondering, is there any common mistake you know of, that could explain this loss in performance? Or tips that generally help? Thanks again!

davidbrochart commented 3 years ago

@joouha has implemented a really nice ScrollingContainer that would be a great contribution to prompt-toolkit, see https://github.com/joouha/euporie/issues/6.