-
Notifications
You must be signed in to change notification settings - Fork 570
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
optimize rendering of results by avoiding console.print #2559
Comments
then again, the output for my test file was a few thousands of lines, which is not the typical case (nor wanted), so maybe this is not really worth spending time on. |
I think that's feasible. Rich allows capturing output via StringIO. |
good point. i'm not sure if the performance issue is:
writing to a console backed by StringIO and then flushing it at the end sounds pretty nice and also easy to try. |
using StringIO directly with a console instance didn't make a meaningful difference in runtime. Therefore, my suspicion is that rich's |
The assessment about |
using line-profiler, I found that functions like
render_feature
can be fairly expensive, taking many seconds (cumulatively) to emit their results to the terminal. Digging into this further, it seems that rich'sconsole.print()
is relatively slow, taking around 100x longer than intermediate string constructions. This means that when we do a lot of littleconsole.print
calls on parts of a line then performance is poor.We can optimize this by constructing complete regions or lines up front, and then flushing to the terminal with
console.print
. I think that rich'sText.append
is still not very fast, but its better than doing a terminal write.Originally we used a StringIO-based strategy of building a large output document and then flushing it in one go (rich-unaware). We might want to migrate back in this direction a little bit.
The text was updated successfully, but these errors were encountered: