Skip to content

discard pending console output on interrupt - #12061

Closed
kevinushey wants to merge 4 commits into
mainfrom
bugfix/console-output-discard-on-interrupt
Closed

kevinushey wants to merge 4 commits into
mainfrom
bugfix/console-output-discard-on-interrupt

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Intent

Addresses #12059.

Approach

Relatively straightforward wiring of callbacks into our existing interrupt handlers:

  • The rConsoleInterrupted callback sends a client event notifying that an interrupt was sent,
  • The client processes that event eagerly, and uses that as a signal to discard any pending output

Automated Tests

Not included.

QA Notes

Test via notes in #12059.

Checklist

  • If this PR adds a new feature, or fixes a bug in a previously released version, it includes an entry in NEWS.md
  • If this PR adds or changes UI, the updated UI meets accessibility standards
  • A reviewer is assigned to this PR (if unsure who to assign, check Area Owners list)
  • This PR passes all local unit tests

@jeffvroom

Copy link
Copy Markdown
Contributor

A concern I have about this fix is that it's designed for this specific test case, where all pending console output is not important. If we use transactional semantics, when pressing 'stop', I'd expect to see any pending console output that was generated before I pressed stop and here that all gets discarded. Perhaps the real problem here is that we can create an arbitrarily long buffer of console output events. There's a fixed cost for each one and we have no way to bound the latency debt that's created when a program is spewing output as fast as it can.

Do we have code to merge console output events on the server side, and somehow join them together on the client if they are coming faster than we can process? That would allow us to overall handle more console output events.

As a second measure, we could have a max pending console output setting and discard the oldest output when more than that comes in. That way, we'd always have the most recent output right up until the 'stop' was pressed but wouldn't let the latency get too long.

@kevinushey

Copy link
Copy Markdown
Collaborator Author

Do we have code to merge console output events on the server side, and somehow join them together on the client if they are coming faster than we can process? That would allow us to overall handle more console output events.

We don't, but that's a good idea. It also raises the question of "why does it take the client so long to process console output?" and it seems like the majority of time is just spent counting lines:

Screen Shot 2022-09-30 at 9 57 00 AM

It looks like we're counting lines here using a plain regular expression, so we could almost surely do better with a plain loop using charCodeAt().

/**
*
* @param node
* @param pre Count hard returns in text nodes as newlines (only true if
* white-space mode is pre*)
* @return
*/
public static int countLines(Node node, boolean pre)
{
switch (node.getNodeType())
{
case Node.TEXT_NODE:
return countLinesInternal((Text)node, pre);
case Node.ELEMENT_NODE:
return countLinesInternal((Element)node, pre);
default:
return 0;
}
}
private static int countLinesInternal(Text textNode, boolean pre)
{
if (!pre)
return 0;
String value = textNode.getData();
Pattern pattern = Pattern.create("\\n");
int count = 0;
Match m = pattern.match(value, 0);
while (m != null)
{
count++;
m = m.nextMatch();
}
return count;
}
private static int countLinesInternal(Element elementNode, boolean pre)
{
if (elementNode.getTagName().equalsIgnoreCase("br"))
return 1;
int result = 0;
NodeList<Node> children = elementNode.getChildNodes();
for (int i = 0; i < children.getLength(); i++)
result += countLines(children.getItem(i), pre);
return result;
}

It's also probably slow to count lines in the text nodes themselves rather on the strings we're getting from the server; it's worth exploring if we can alleviate that cost as well.

I'll try to see if we can make progress with those before dropping potential output. Thank you!

@kevinushey

Copy link
Copy Markdown
Collaborator Author

Superceded by #12077.

@kevinushey kevinushey closed this Oct 1, 2022
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.

2 participants