-
Notifications
You must be signed in to change notification settings - Fork 52
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
Writing the world map to JTextPane is sometimes too slow #176
Comments
http://javatechniques.com/blog/faster-jtextpane-text-insertion-part-i/ has some fantastic insights into this issue. Basically, there are two causes for slow JTextPane updates: each insertion triggers a re-rendering of the display and some methods in the DefaultStyledDocument class are synchronized, so there is the overhead of acquiring locks. I will work around the first issue and see if it is enough, it should be. The current idea is to keep two identical StyledDocuments. One is set to the text pane while the other awaits for an update. When we need to write something new, we first update the one that is resting. Then set it to the pane, then update the other one. Note to self: remember to check that clearTextPane() clears both documents. Also check that everything that currently changes these documents will work with the new structure. Maybe even write a class that handles these update mechanism for the window. The GameWindow class already does too much. That class would encapsulate implementation details and provide a write method. It would then perform the write-swap-write idea behind the scenes. |
Microbenchmarking results for my first implementation of the solution Old:
New:
|
Acceptable results. One of the things that makes the first debug map command so slow is that it usually triggers the creation of several new locations. |
Wrote an extra command to better benchmark the performance improvement. On Ubuntu 14.04 using OpenJDK 1.7.0_85, I got the following: Old:
New:
|
I suppose that for smaller pieces of text the new method may be just as good as, or even worse, than the old one (just updating the current Document of the JTextPane). However, the problem is only present for larger amounts of output, so this fix is good for now and will be merged into master. |
I've had some really poor performance with some dense maps being written.
The text was updated successfully, but these errors were encountered: