This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
CachedInputStream implements only single-byte read method, and while a bunch of sniffing resolvers could end up doing just a bunch of arraycopy()s, they instead always go through complicated caching logic for each byte they require. We currently have 12 magic-based mime resolvers that end up doing 186 single-byte read operations on the underlaying stream, and that is for each recognized file in a folder. In my profile, the IDE consumed 2s in mime resolution of 120 java files, 1s (out of that 2s) just in the CachedInputStream. (22056 calls in total). You need to implement the bulk read method.
... an I don't want to know what will happen with xml sniffing mime resolvers, which tend to process much larger chunks of data. This bug should be quite simple to fix.
Need more profiling. It might be the case that although the single byte read() gets called many times, the time is actually spent in the underlaying JDK+native read method (clod caches). Anyway, it won't hurt to have read(byte[], int, int) implemented, it's just 10 or so lines of code.
Created attachment 50066 [details] pathc for read impl.
The patch is OK though a bit confusing: int buflen = Math.max(len, blen); buflen = (buflen > 0) ? (buflen * 2) : 256; It works only because pos is never more than len. I would expect the first line would read "int buflen = pos+blen" (which is always more than len) and the second line can never take the ":256" branch anyway. Well, it can, if len=0 and blen=0, but such case (just for correctness, I don't expect anybody calling it this way) should be covered by the initial if, which should, in fact read boolean isCached = (pos + blen <= len); // less or EQUALS I'd refactor the buffer refill into a separate routine used from both read methods, though.
/cvs/openide/fs/src/org/openide/filesystems/MIMESupport.java,v <-- MIMESupport.java new revision: 1.23; previous revision: 1.22 Patch slightly modified and fixed.
Rollback - reopened
/cvs/openide/fs/src/org/openide/filesystems/MIMESupport.java,v <-- MIMESupport.java new revision: 1.25; previous revision: 1.24