-
Bug
-
Resolution: Unresolved
-
P3
-
None
-
6
-
x86
-
windows_vista
FULL PRODUCT VERSION :
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Windows Vista
A DESCRIPTION OF THE PROBLEM :
Text components were component orientation is set to RTL (right to left) are much slower (text insert) and consume much more memory compared to LTR orientation.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the test case and press the start button - the result is printed at the console:
Time: 172 ms, Used Memory: 2,40 MB, Free Memory: 2,54 MB
Select RTL checkbox and press the start button again - the result at the console:
Time: 5819 ms, Used Memory: 37,03 MB, Free Memory: 13,90 MB
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Nearly same memory and performance as with LTR.
ACTUAL -
Execution time for RTL component is about 30 times slower and needs much more memory.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.ComponentOrientation;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class RTLMemoryAndPerformanceTest extends JFrame
{
private static final int LINES = 4000;
private JTextArea ta = new JTextArea();
private JScrollPane scroller = new JScrollPane(ta);
private long start;
public static void main(String[] args) throws Exception
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
new RTLMemoryAndPerformanceTest();
}
});
}
public RTLMemoryAndPerformanceTest()
{
add(scroller);
JPanel panel = new JPanel();
final JCheckBox cb = new JCheckBox("RTL");
JButton button = new JButton(new AbstractAction("Start")
{
public void actionPerformed(ActionEvent evt)
{
final JButton button = (JButton)evt.getSource();
new Thread()
{
public void run()
{
for (int i=0; i<LINES; i++)
{
final int line = i+1;
EventQueue.invokeLater(new Runnable()
{
public void run()
{
if (line == 1)
{
//Memory won't get GC'd when switching from RTL to LTR - for some reason a new text area instance is necessary!
//ta.setText(" ");
ta = new JTextArea();
scroller.setViewportView(ta);
button.setEnabled(false);
scroller.applyComponentOrientation(cb.isSelected() ? ComponentOrientation.RIGHT_TO_LEFT : ComponentOrientation.LEFT_TO_RIGHT);
}
ta.append("abcdefghijklmnopqrstuvwxyz01234567890\n");
if (line == LINES)
{
long end = System.currentTimeMillis();
button.setEnabled(true);
float free = Runtime.getRuntime().freeMemory()/1024f/1024f;
float total = Runtime.getRuntime().totalMemory()/1024f/1024f;
System.err.format("Time: %d ms, Used Memory: %.2f MB, Free Memory: %.2f MB%n", end-start, total-free, free);
}
}
});
//give EDT some extra time for updating GUI
if (line == 1)
{
System.gc();
try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
start = System.currentTimeMillis();
}
}
}
}.start();
}
});
panel.add(button);
panel.add(cb);
add(panel, BorderLayout.SOUTH);
setTitle(this.getClass().getSimpleName());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400, 300);
setLocationRelativeTo(null);
setVisible(true);
}
}
---------- END SOURCE ----------
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Windows Vista
A DESCRIPTION OF THE PROBLEM :
Text components were component orientation is set to RTL (right to left) are much slower (text insert) and consume much more memory compared to LTR orientation.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the test case and press the start button - the result is printed at the console:
Time: 172 ms, Used Memory: 2,40 MB, Free Memory: 2,54 MB
Select RTL checkbox and press the start button again - the result at the console:
Time: 5819 ms, Used Memory: 37,03 MB, Free Memory: 13,90 MB
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Nearly same memory and performance as with LTR.
ACTUAL -
Execution time for RTL component is about 30 times slower and needs much more memory.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.ComponentOrientation;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class RTLMemoryAndPerformanceTest extends JFrame
{
private static final int LINES = 4000;
private JTextArea ta = new JTextArea();
private JScrollPane scroller = new JScrollPane(ta);
private long start;
public static void main(String[] args) throws Exception
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
new RTLMemoryAndPerformanceTest();
}
});
}
public RTLMemoryAndPerformanceTest()
{
add(scroller);
JPanel panel = new JPanel();
final JCheckBox cb = new JCheckBox("RTL");
JButton button = new JButton(new AbstractAction("Start")
{
public void actionPerformed(ActionEvent evt)
{
final JButton button = (JButton)evt.getSource();
new Thread()
{
public void run()
{
for (int i=0; i<LINES; i++)
{
final int line = i+1;
EventQueue.invokeLater(new Runnable()
{
public void run()
{
if (line == 1)
{
//Memory won't get GC'd when switching from RTL to LTR - for some reason a new text area instance is necessary!
//ta.setText(" ");
ta = new JTextArea();
scroller.setViewportView(ta);
button.setEnabled(false);
scroller.applyComponentOrientation(cb.isSelected() ? ComponentOrientation.RIGHT_TO_LEFT : ComponentOrientation.LEFT_TO_RIGHT);
}
ta.append("abcdefghijklmnopqrstuvwxyz01234567890\n");
if (line == LINES)
{
long end = System.currentTimeMillis();
button.setEnabled(true);
float free = Runtime.getRuntime().freeMemory()/1024f/1024f;
float total = Runtime.getRuntime().totalMemory()/1024f/1024f;
System.err.format("Time: %d ms, Used Memory: %.2f MB, Free Memory: %.2f MB%n", end-start, total-free, free);
}
}
});
//give EDT some extra time for updating GUI
if (line == 1)
{
System.gc();
try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
start = System.currentTimeMillis();
}
}
}
}.start();
}
});
panel.add(button);
panel.add(cb);
add(panel, BorderLayout.SOUTH);
setTitle(this.getClass().getSimpleName());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400, 300);
setLocationRelativeTo(null);
setVisible(true);
}
}
---------- END SOURCE ----------