Skip to content

Conversation

@jonathanpeppers
Copy link
Member

When reviewing ResolveLibraryProjectImports, I noticed a few things
we could improve:

  1. We are using GetResourceData to get the entire contents of a file
    as a byte[] and then writing to disk.
  2. We are writing temporary zip files to disk, reading them to extract,
    then deleting them.

The first thing I did was take advantage of the GetResourceStream
method, so we could just do stream.CopyTo(file). This prevents us
from allocating big byte[] the size of each file.

Next, I took advantage of ZipArchive.Open (stream) and
GetResourceStream to avoid the need for creating temporary zip
files. We can unzip directly from the Stream in memory.

Results

When timing these changes, I used the Xamarin.Forms integration
project in this repo:

Before
1. 1793 ms  ResolveLibraryProjectImports               1 calls
2. 1780 ms  ResolveLibraryProjectImports               1 calls
3. 1770 ms  ResolveLibraryProjectImports               1 calls
After
1. 1750 ms  ResolveLibraryProjectImports               1 calls
2. 1740 ms  ResolveLibraryProjectImports               1 calls
3. 1702 ms  ResolveLibraryProjectImports               1 calls

I would say the improvements here are around 50ms.

@dellis1972
Copy link
Contributor

Not going to merge since we do not have any build system atm :/

@jonathanpeppers
Copy link
Member Author

build

When reviewing `ResolveLibraryProjectImports`, I noticed a few things
we could improve:

1. We are using `GetResourceData` to get the entire contents of a file
  as a `byte[]` and then writing to disk.
2. We are writing temporary zip files to disk, reading them to extract,
  then deleting them.

The first thing I did was take advantage of the `GetResourceStream`
method, so we could just do `stream.CopyTo(file)`. This prevents us
from allocating big `byte[]` the size of each file.

Next, I took advantage of `ZipArchive.Open (stream)` and
`GetResourceStream` to avoid the need for creating temporary zip
files. We can unzip directly from the `Stream` in memory.

~~ Results ~~

When timing these changes, I used the Xamarin.Forms integration
project in this repo:

    Before
    1. 1793 ms  ResolveLibraryProjectImports               1 calls
    2. 1780 ms  ResolveLibraryProjectImports               1 calls
    3. 1770 ms  ResolveLibraryProjectImports               1 calls
    After
    1. 1750 ms  ResolveLibraryProjectImports               1 calls
    2. 1740 ms  ResolveLibraryProjectImports               1 calls
    3. 1702 ms  ResolveLibraryProjectImports               1 calls

I would say the improvements here are around 50ms.
@jonathanpeppers jonathanpeppers force-pushed the resolvelibraryprojectimports-tempfiles branch from aeda0e2 to bebb5ea Compare December 18, 2018 03:03
@jonpryor jonpryor merged commit e2abfcd into dotnet:master Dec 19, 2018
jonathanpeppers added a commit that referenced this pull request Jan 2, 2019
…#2540)

When reviewing the `<ResolveLibraryProjectImports/>` task, I noticed
a few things we could improve:

 1. We are using `GetResourceData()` to get the entire contents of a
    file as a `byte[]` and then writing to disk.
 2. We are writing temporary zip files to disk, reading them to
    extract, then deleting them.

The first thing I did was take advantage of the `GetResourceStream()`
method, so we could just do `stream.CopyTo(file)`.  This prevents us
from allocating big `byte[]` the size of each file.

Next, I took advantage of `ZipArchive.Open(stream)` and
`GetResourceStream()` to avoid the need for creating temporary zip
files.  We can unzip directly from the `Stream` in memory.

~~ Results ~~

When timing these changes, I used the Xamarin.Forms integration
project in this repo:

	Before
	1. 1793 ms  ResolveLibraryProjectImports               1 calls
	2. 1780 ms  ResolveLibraryProjectImports               1 calls
	3. 1770 ms  ResolveLibraryProjectImports               1 calls

	After
	1. 1750 ms  ResolveLibraryProjectImports               1 calls
	2. 1740 ms  ResolveLibraryProjectImports               1 calls
	3. 1702 ms  ResolveLibraryProjectImports               1 calls

I would say the improvements here are around 50ms.
@jonathanpeppers jonathanpeppers deleted the resolvelibraryprojectimports-tempfiles branch January 4, 2019 17:37
@github-actions github-actions bot locked and limited conversation to collaborators Feb 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants