Community
Participate
Working Groups
There are several places in our code where we use InputStreamReader. The comment for this class states: * <p> For top efficiency, consider wrapping an InputStreamReader within a * BufferedReader. For example: * * <pre> * BufferedReader in * = new BufferedReader(new InputStreamReader(System.in)); * </pre> See load(String) - org.eclipse.jface.dialogs.DialogSettings loadAssociations() - org.eclipse.ui.internal.registry.EditorRegistry (2 matches) loadCustomPersp(PerspectiveDescriptor) - org.eclipse.ui.internal.Perspective loadDialogSettings() - org.eclipse.ui.plugin.AbstractUIPlugin openPreviousWorkbenchState() - org.eclipse.ui.internal.Workbench PerspectiveDescriptor(File) - org.eclipse.ui.internal.registry.PerspectiveDescriptor restoreState() - org.eclipse.ui.internal.WorkingSetManager
It would be good to have some numbers backing this up.
Performance varies depending on the disk system (e.g., networked drives are horrible) and whether or not the file is in the disk cache. On my TP with the file in the cache, buffered is more than 2x faster than non-buffered. The result is more impressive when the file is not in the cache. Core and JDT did a pass of making everything buffered in the 1.0 timeframe. Eventhough the volume of data read by the UI is probably not that great the change is simple and low risk. See the test code below. For a 3.5MB file the numbers are: testing... non buffered 1713 buffered 761 import java.io.*; public class BufferTest { public static void main(String[] args) throws Exception { long start = 0; System.out.println ("testing..."); Reader in = new InputStreamReader(new FileInputStream("test")); start = System.currentTimeMillis(); while (in.read() != -1) {} System.out.println ("non buffered " + (System.currentTimeMillis() - start)); in.close(); in = new BufferedReader (new InputStreamReader(new FileInputStream ("test"))); start = System.currentTimeMillis(); while (in.read() != -1) {} System.out.println ("buffered " + (System.currentTimeMillis() - start)); in.close(); } }
Should fix for 2.1. There may be others now too.
BufferedReader wraps InputStreamReader in 20021120 build
Note that BufferedReaders need not be used when using a StringReader, since the reading is all done in memory anyway. Noticed this in the changes to EditorRegistry. There may be other places.
Fixed in 20021123 build
Verified fixed in build 20021216. However, there are new places that don't use BufferedReader. Opened bug 28585.