Skip to content

Commit a172402

Browse files
authored
[class-parse] Use BufferedStream to increase performance (#1092)
While building `AndroidX.sln`, `class-parse` is taking up a considerable amount of time. After some quick profiling, this seems to be caused by reading from a `ZipStream` one or two bytes at a time. Wrapping the `ZipStream` in a `BufferedStream` makes `class-parse` about 10x faster on larger test cases. | | 0d5cddb | Now | | --------------------------------------------------------------- | --------: | --------: | | `class-parse` on API-33 `android.jar` (26.5 MB) | 16.675s | 2.759s | | `class-parse` on `androidx.compose.runtime.runtime` (1.044 MB) | 9.713s | .893s | | Total `class-parse` time building `AndroidX.sln` | 5:48.46m | 2:09.73m | | Total time building `AndroidX.sln` | 7:40.19m | 4:42.34m |
1 parent 0355acf commit a172402

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/Xamarin.Android.Tools.Bytecode/ClassPath.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public void Load (Stream jarStream, bool leaveOpen = false)
7272
if (!ClassFile.IsClassFile (s) || entry.Name.EndsWith (".jnilib", StringComparison.OrdinalIgnoreCase))
7373
continue;
7474
}
75-
using (var s = entry.Open ()) {
75+
using (var entry_stream = entry.Open ())
76+
using (var s = new BufferedStream (entry_stream)) {
7677
try {
7778
var c = new ClassFile (s);
7879
Add (c);

0 commit comments

Comments
 (0)