Skip to content

Conversation

yihong0618
Copy link
Contributor

@yihong0618 yihong0618 commented Oct 1, 2025

The root cause of the this lis the calc_screen() method of reader.py. When screen, screeninfo, and line_end_offsets are retrieved from the cache, they are passed by direct reference instead of by a copy.

before this patch

2025-10-01.12.31.25.mov

after this patch

2025-10-01.12.57.17.mov

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
del screeninfo[num_common_lines:]

last_refresh_line_end_offsets = self.last_refresh_cache.line_end_offsets
last_refresh_line_end_offsets = self.last_refresh_cache.line_end_offsets.copy()
Copy link

@kemingy kemingy Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this last_refresh_line_end_offsets has never been used in this function. The bug can be fixed by deleting this one.

The other two screen & screeninfo are synced back to self.last_refresh_cache. But for readability & maintenance, we should copy them here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

@kemingy
Copy link

kemingy commented Oct 1, 2025

The failed Windows test (test.test_pyrepl.test_windows_console.WindowsConsoleTests.test_multiline_ctrl_z) is not caused by this PR.

If we add the reader.screeninfo to the assert msg:

- (4, 2)
+ (2, 3) : [(0, [1, 1, 1, 1, 1]), (0, [1, 1, 1, 1, 1]), (0, [1, 2, 1])]

yihong0618 and others added 2 commits October 1, 2025 18:48
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Co-authored-by: Keming <kemingy94@gmail.com>
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
offset, num_common_lines = self.last_refresh_cache.get_cached_location(self)

screen = self.last_refresh_cache.screen
screen = self.last_refresh_cache.screen.copy()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A copy is expensive if we do it at every refresh. Isn't there an alternate way to do it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for my first try copy is fine here, since its only in repl

and then will try to figure out if there is a better way.
thanks for the info

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that people want the REPL not to be slow in general. What's the maximum size of screen? if there are only a few string items (and if this is upper-bounded by the terminal size), then it should relatively be fine.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One possible way is to keep using the reference instead of the copy, since these two variables will eventually be synced back to the self.last_refresh_cache. We can add some comments to explain this decision in the code to avoid misunderstanding for others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants