groovy/groovy-core — pull request #344 by andresteingress (2014-03-07 12:31:20+00:00)
Title: GROOVY-6579: Groovy Console not responsive when running the closure

As described in 6579, groovyConsole almost always hangs for scripts that execute many writes on stdout/stderr (the issue mentions an example where `println` is called 200 times). The reason is that there is no buffering between writing to output streams and insertions into the underlying (slow) Swing `HtmlDocument`. I had a look at the IntelliJ console but they solve the issue with self-written panels for example.

This fix introduces buffered output between calls to stdout/stderr and HtmlDocument. The buffered output is either written to the `HtmlDocument` with an explicit `flush()` or if the buffer is full. For long running scripts, groovyConsole additionally uses the `OutputStreamSynchronisation` class that periodically calls `flush()` on stdout and stderr (every 250ms is the default setting here). This has the consequence of less frequent HtmlDocument modifications and improved performance.

I tested the changes on Mac OS X and Windows 7, had it running on JDK 7 and JDK 6.

The rendering issues described in GROOVY-4096 which introduced the `doc.remove` calls have not been reproducible on Windows for me, so I assumed this was a JDK rendering issue at the time. I removed the calls because they did eat a specific amount of performance for larger HTML documents.