Skip to content

Feature/virtual scroller - #7568

Merged
adamconroy merged 10 commits into
masterfrom
feature/virtual-scroller
Sep 2, 2020
Merged

adamconroy merged 10 commits into
masterfrom
feature/virtual-scroller

Conversation

@adamconroy

Copy link
Copy Markdown
Contributor

Intent

Improve performance of the Console pane when a large amount of data has accumulated in that window.

Fixes #6042

Approach

Only show a moving window of message elements much like Slack and other similar programs. When scrolling up/down a set of elements (stored in "buckets") is added to the view while another bucket on the opposite end is hidden.

QA Notes

There is a lot of subtle DOM manipulation added to the console functionality here. It's fairly self-contained but it is very possible that there are cases where GWT code is trying to directly manipulate the DOM that I missed.

I think just putting as much varied content as possible into the console is the best place to start for testing. I'll be available to work closely with ya'll for testing here because it is such a quirky feature.

this._MAX_VISIBLE_BUCKETS = 10;

// we use this style to keep the elements in the DOM for screen readers
this._HIDDEN_STYLE = "org-rstudio-core-client-theme-res-ThemeStyles-visuallyHidden";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Have you tested this in a production build? GWT obfuscates class names, so you will either need to pass the class name into the setup method at runtime or tell GWT to use a non-obfuscated name.

return;

// *** _CONSTANTS ***
this._DEBUG = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be disabled by default?

this._DEBUG = true;
this._SCROLL_DEBOUNCE_MS = 500;
this._BUCKET_MAX_SIZE = 50;
this._MAX_VISIBLE_BUCKETS = 10;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These parameters are probably somewhat machine dependent (i.e. with more hardware you can have more buckets w/o noticeable performance degradation), so it'd be nice if they could be set via an advanced (no UI) option; your call.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I partially also picked this due to it just feeling better, in my opinion, to have a smaller scrollbar and having more fine motor control over what you see in the window. Once the window becomes saturated it's quite difficult to quickly get to the line that you want, it's why I clear in my terminal pretty often.

I'll file an enhancement to make this customizable though.

@gtritchie gtritchie Aug 13, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's also interaction with our server-side (I think) console-output limiting logic to consider. For example, try this sequence:

> for (i in 1:2000) cat(c(i, "\n"))
1000
1001
...
2000

Notice that you only see the output from 1000 - 2000 (but still see the original prompt with no indication stuff is missing in between; prior to this change the prompt would have been lost, too).

> for (i in 2001:4000) cat(c(i, "\n"))
3000
3001
...
4000

Now you can scroll back and indeed are seeing > 1000 lines, but these gaps are unexpected, I think.

this.jumpToLatestButton.onclick = function() {
self._jumpToBottom();
self._setJumpToLatestVisible(false);
document.getElementById("rstudio_console_output").focus();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This would need to be removed to make the virtual scroller usable in other panes. Maybe it should be supplied as a callback?

// only load the virtual scroller if enabled in prefs
if (prefs_.limitConsoleVisible() &&
parent_ != null &&
!VirtualConsole.virtualScrollerInitialized_ &&

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: VirtualConsole. prefix is unnecessary (here and elsewhere)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I really like prefixing it to make it explicit that we're referencing something static but if it's not how we do it in our style guide that's fine.


private static final ExternalJavaScriptLoader virtualScrollerLoader_ =
new ExternalJavaScriptLoader(VirtualScrollerResources.INSTANCE.virtualscrollerjs().getSafeUri().asString());
private static VirtualScrollerNative virtualScrollerNative_;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe I'm misreading this, but wouldn't we need one instance of VirtualScrollerNative per VirtualConsole?

@adamconroy adamconroy Aug 13, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in the commit I just pushed. Unfortunately just making it an instance variable wasn't an option as the way that VirtualConsole works is frankly kind of broken. A new instance is created pretty much any time you hit enter and there's a lot of cases where it's created with a null parent. I tried to decouple it from Gin but I wasn't able to make a clean break there so I wholly detached VirtualScroller from the VirtualConsole, which I prefer anyway.

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some initial comments; I still need to do accessibility testing but want to get this feedback written down in the meantime.

if (prefs_.limitVisibleConsole().getValue() != initialLimitVisibleConsole_)
{
initialLimitVisibleConsole_ = prefs_.limitVisibleConsole().getValue();
if (Desktop.isDesktop())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can replace this if/else with a single call to restartRequirement.setRestartRequired() (added fairly recently).

range.appendRight(text, 0);
}
else
} else

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit, we usually put else on a separate line

@Override
public boolean limitConsoleVisible()
{
return limitConsoleVisible_;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As discussed elsewhere, be great to have some unit-tests for the virtual scrolling mechanism here and/or in the ConsoleOutputWriteTests.

this._DEBUG = true;
this._SCROLL_DEBOUNCE_MS = 500;
this._BUCKET_MAX_SIZE = 50;
this._MAX_VISIBLE_BUCKETS = 10;

@gtritchie gtritchie Aug 13, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's also interaction with our server-side (I think) console-output limiting logic to consider. For example, try this sequence:

> for (i in 1:2000) cat(c(i, "\n"))
1000
1001
...
2000

Notice that you only see the output from 1000 - 2000 (but still see the original prompt with no indication stuff is missing in between; prior to this change the prompt would have been lost, too).

> for (i in 2001:4000) cat(c(i, "\n"))
3000
3001
...
4000

Now you can scroll back and indeed are seeing > 1000 lines, but these gaps are unexpected, I think.

@gtritchie

Copy link
Copy Markdown
Member

Mentioned this in Slack, including here for completeness:

Seeing a bug; after running (for example: for (i in 1:500) message(i), then reloading the browser page, the console output isn’t reloaded (console is blank). Same with Desktop (e.g. right-click on blank area of toolbar and “reload”).

Works when I turn off the option you added.

@gtritchie

Copy link
Copy Markdown
Member

The accessibility command focusConsoleOutputEnd (shortcut is Ctrl+`) is not working when the virtual scroller is on; nothing happens. When virtual console is disabled, it works as expected and puts keyboard focus on the console output region.

@@ -0,0 +1,106 @@
package org.rstudio.core.client.virtualscroller;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: missing comment header

{
// If we get an error initializing the virtualScroller, log
// and no-op the error to continue non-virtualized
Debug.log(e.getMessage());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we clear the loading_ flag here? (doesn't look like it effects correctness but would be consistent?)

@kevinushey

Copy link
Copy Markdown
Collaborator

I tried running:

for (i in 1:10000) cat(i, "\n")

and saw some discontinuities in the output:

Screen Shot 2020-08-17 at 10 26 55 AM

Screen Shot 2020-08-17 at 10 26 34 AM

Seems as though some buckets of output are being dropped?

@adamconroy

Copy link
Copy Markdown
Contributor Author

This isn't done yet but I've been working on it as I can between support tickets. I just pushed the nitpick fixes and did a merge to have them in and updated.

As of now:

  1. Missing/truncated long lines: I'm still trying to figure out the best way to solve this. The problem is that the truncation is happening in-situ after the bucket is already added kind of out of the control of the VirtualScroller itself. I'm not actually sure why this is messing up because there is only ever one bucket and the content inside of them is corrupted. It's pretty frustrating because I think there's a confluence between the server side and everything on the frontend as Gary suspected.
  2. Focus Console keyboard shortcut: This one is funky due to the way that I'm separating the bucketed content from the input textarea. I'm trying to find the right incantation to get a reference to that textarea itself but it's not immediately obvious.
  3. Content being lost on restart: I did not have this issue when I created the PR as I did extensive testing on reallocating the saved content on VirtualScroller initialization (see everything that happens in the constructor/setup() function). Unfortunately I cannot test this easily right now as my R session has been crashing without fail on Reload ever since my last merge. I'm going to have to reach out to get help on this because I have no idea what's causing it, it is also happening on Master for me.

@adamconroy

Copy link
Copy Markdown
Contributor Author

So, been a stressful week debugging this stuff. Items 2 and 3 above weren't too bad, about a day each to figure out the right solutions for. Item 1 however...

So the issue is that the data has no fewer than 5 (and maybe a 6th) different states that need to stay in sync: backend caching, frontend StringBuilder, frontend output Element, frontend bucket, frontend line_ variable. In addition to this, the backend seems to be doing some hidden trimming/data omission that I haven't yet found (beyond it's normal maxOutputLines trimming) such that not all of the data even ever makes it to the "ConsoleProcess::onStdout" function. There may be a layer deeper in the R that I haven't delved into yet that's doing this omission but that will take more time.

The good news is now there is no data that would ever be shown in the old way that is ever lost while VirtualScroller is active. The remaining symptom is that single output chunks over 1000 lines seem to have some missing data but it's data you can't currently ever access anyway as these missing chunks are only before the final 1000 lines. I propose filing a bug for this issue as it may actually indicate something more insidious going on in a deeper lever of the ConsoleProcess and moving on from here.

@gtritchie @kevinushey this should be ready to be looked at again. Thank you for your patience.

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@kevinushey

Copy link
Copy Markdown
Collaborator

@adamconroy: are you able to confirm that the example I described in #7568 (comment) is fixed? If not, I think that needs to be handled before this PR is merged. (I wasn't sure if it is indeed resolved or not based on your comment)

@adamconroy

adamconroy commented Sep 2, 2020 •

Copy link
Copy Markdown
Contributor Author

Talked with Kevin and Jonathan and we are going to merge and file this as an issue to fix ASAP.

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.

Improve speed of console when it contains a lot of output

4 participants