Massively optimized MobileProvisionIndex by using custom data structures (#14)

* Massively optimized MobileProvisionIndex by using custom data structures

The problem with using a PList is that when you have massive
PArrays of dev certs, it causes saving the plist to be unusably
slow due to all of the linear lookups to get the indexes.

There was also overhead of PDictionary over the use of direct
int/string/etc properties.

Fixes perf found in https://bugzilla.xamarin.com/show_bug.cgi?id=58678
This commit is contained in:
Jeffrey Stedfast 2017-08-14 15:03:40 -04:00 коммит произвёл GitHub
Родитель da6aeb0f49
Коммит e3da1b5212
7 изменённых файлов: 497 добавлений и 419 удалений

Двоичный файл не отображается.

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,110 @@
//
// TestMobileProvisionIndex.cs
//
// Author: Jeffrey Stedfast <jestedfa@microsoft.com>
//
// Copyright (c) 2017 Microsoft Corp.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.IO;
using NUnit.Framework;
using Xamarin.MacDev;
namespace UnitTests
{
[TestFixture]
public class TestMobileProvisionIndex
{
[Test]
public void TestCreateIndex ()
{
var index = MobileProvisionIndex.CreateIndex ("../../TestData/Provisioning Profiles", "profiles.index");
Assert.AreEqual (2, index.ProvisioningProfiles.Count);
Assert.AreEqual ("YHT9CR87YA.com.companyname.*", index.ProvisioningProfiles[0].ApplicationIdentifier);
Assert.AreEqual (new DateTime (2017, 07, 19, 19, 43, 45, DateTimeKind.Utc), index.ProvisioningProfiles[0].CreationDate);
Assert.AreEqual (1, index.ProvisioningProfiles[0].DeveloperCertificates.Count);
Assert.AreEqual ("iPhone Developer: Jeffrey Stedfast (FZ77UAV9SW)", index.ProvisioningProfiles[0].DeveloperCertificates[0].Name);
Assert.AreEqual ("2097D37F4D16AB7D8D927E7C1872F2A94D8DC718", index.ProvisioningProfiles[0].DeveloperCertificates[0].Thumbprint);
Assert.AreEqual (MobileProvisionDistributionType.Development, index.ProvisioningProfiles[0].Distribution);
Assert.AreEqual (new DateTime (2018, 07, 19, 19, 43, 45, DateTimeKind.Utc), index.ProvisioningProfiles[0].ExpirationDate);
Assert.AreEqual ("29cbf4b4-a170-4c74-a29a-64ecd55b102e.mobileprovision", Path.GetFileName (index.ProvisioningProfiles[0].FileName));
//Assert.AreEqual (index.ProvisioningProfiles[0].LastModified);
Assert.AreEqual ("CompanyName Development Profile", index.ProvisioningProfiles[0].Name);
Assert.AreEqual (1, index.ProvisioningProfiles[0].Platforms.Count);
Assert.AreEqual (MobileProvisionPlatform.iOS, index.ProvisioningProfiles[0].Platforms[0]);
Assert.AreEqual ("29cbf4b4-a170-4c74-a29a-64ecd55b102e", index.ProvisioningProfiles[0].Uuid);
Assert.AreEqual ("YHT9CR87YA.com.xamarin.*", index.ProvisioningProfiles[1].ApplicationIdentifier);
Assert.AreEqual (new DateTime (2017, 07, 19, 19, 44, 0, DateTimeKind.Utc), index.ProvisioningProfiles[1].CreationDate);
Assert.AreEqual (1, index.ProvisioningProfiles[1].DeveloperCertificates.Count);
Assert.AreEqual ("iPhone Developer: Jeffrey Stedfast (FZ77UAV9SW)", index.ProvisioningProfiles[1].DeveloperCertificates[0].Name);
Assert.AreEqual ("2097D37F4D16AB7D8D927E7C1872F2A94D8DC718", index.ProvisioningProfiles[1].DeveloperCertificates[0].Thumbprint);
Assert.AreEqual (MobileProvisionDistributionType.Development, index.ProvisioningProfiles[1].Distribution);
Assert.AreEqual (new DateTime (2018, 07, 19, 19, 44, 0, DateTimeKind.Utc), index.ProvisioningProfiles[1].ExpirationDate);
Assert.AreEqual ("7079f389-6ff4-4290-bf76-c8a222947616.mobileprovision", Path.GetFileName (index.ProvisioningProfiles[1].FileName));
//Assert.AreEqual (index.ProvisioningProfiles[0].LastModified);
Assert.AreEqual ("Xamarin Development Profile", index.ProvisioningProfiles[1].Name);
Assert.AreEqual (1, index.ProvisioningProfiles[1].Platforms.Count);
Assert.AreEqual (MobileProvisionPlatform.iOS, index.ProvisioningProfiles[1].Platforms[0]);
Assert.AreEqual ("7079f389-6ff4-4290-bf76-c8a222947616", index.ProvisioningProfiles[1].Uuid);
}
[Test]
public void TestOpenIndex ()
{
var index = MobileProvisionIndex.OpenIndex ("../../TestData/Provisioning Profiles", "profiles.index");
Assert.AreEqual (2, index.ProvisioningProfiles.Count);
Assert.AreEqual ("YHT9CR87YA.com.companyname.*", index.ProvisioningProfiles[0].ApplicationIdentifier);
Assert.AreEqual (new DateTime (2017, 07, 19, 19, 43, 45, DateTimeKind.Utc), index.ProvisioningProfiles[0].CreationDate);
Assert.AreEqual (1, index.ProvisioningProfiles[0].DeveloperCertificates.Count);
Assert.AreEqual ("iPhone Developer: Jeffrey Stedfast (FZ77UAV9SW)", index.ProvisioningProfiles[0].DeveloperCertificates[0].Name);
Assert.AreEqual ("2097D37F4D16AB7D8D927E7C1872F2A94D8DC718", index.ProvisioningProfiles[0].DeveloperCertificates[0].Thumbprint);
Assert.AreEqual (MobileProvisionDistributionType.Development, index.ProvisioningProfiles[0].Distribution);
Assert.AreEqual (new DateTime (2018, 07, 19, 19, 43, 45, DateTimeKind.Utc), index.ProvisioningProfiles[0].ExpirationDate);
Assert.AreEqual ("29cbf4b4-a170-4c74-a29a-64ecd55b102e.mobileprovision", Path.GetFileName (index.ProvisioningProfiles[0].FileName));
//Assert.AreEqual (index.ProvisioningProfiles[0].LastModified);
Assert.AreEqual ("CompanyName Development Profile", index.ProvisioningProfiles[0].Name);
Assert.AreEqual (1, index.ProvisioningProfiles[0].Platforms.Count);
Assert.AreEqual (MobileProvisionPlatform.iOS, index.ProvisioningProfiles[0].Platforms[0]);
Assert.AreEqual ("29cbf4b4-a170-4c74-a29a-64ecd55b102e", index.ProvisioningProfiles[0].Uuid);
Assert.AreEqual ("YHT9CR87YA.com.xamarin.*", index.ProvisioningProfiles[1].ApplicationIdentifier);
Assert.AreEqual (new DateTime (2017, 07, 19, 19, 44, 0, DateTimeKind.Utc), index.ProvisioningProfiles[1].CreationDate);
Assert.AreEqual (1, index.ProvisioningProfiles[1].DeveloperCertificates.Count);
Assert.AreEqual ("iPhone Developer: Jeffrey Stedfast (FZ77UAV9SW)", index.ProvisioningProfiles[1].DeveloperCertificates[0].Name);
Assert.AreEqual ("2097D37F4D16AB7D8D927E7C1872F2A94D8DC718", index.ProvisioningProfiles[1].DeveloperCertificates[0].Thumbprint);
Assert.AreEqual (MobileProvisionDistributionType.Development, index.ProvisioningProfiles[1].Distribution);
Assert.AreEqual (new DateTime (2018, 07, 19, 19, 44, 0, DateTimeKind.Utc), index.ProvisioningProfiles[1].ExpirationDate);
Assert.AreEqual ("7079f389-6ff4-4290-bf76-c8a222947616.mobileprovision", Path.GetFileName (index.ProvisioningProfiles[1].FileName));
//Assert.AreEqual (index.ProvisioningProfiles[0].LastModified);
Assert.AreEqual ("Xamarin Development Profile", index.ProvisioningProfiles[1].Name);
Assert.AreEqual (1, index.ProvisioningProfiles[1].Platforms.Count);
Assert.AreEqual (MobileProvisionPlatform.iOS, index.ProvisioningProfiles[1].Platforms[0]);
Assert.AreEqual ("7079f389-6ff4-4290-bf76-c8a222947616", index.ProvisioningProfiles[1].Uuid);
}
}
}

Просмотреть файл

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{39DBAAF8-57A5-49A3-9E9A-11B545906AED}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>UnitTests</RootNamespace>
<AssemblyName>UnitTests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="nunit.framework">
<HintPath>..\..\..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="TestMobileProvisionIndex.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="TestData\Provisioning Profiles\29cbf4b4-a170-4c74-a29a-64ecd55b102e.mobileprovision" />
<None Include="TestData\Provisioning Profiles\7079f389-6ff4-4290-bf76-c8a222947616.mobileprovision" />
</ItemGroup>
<ItemGroup>
<Folder Include="TestData\" />
<Folder Include="TestData\Provisioning Profiles\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Xamarin.MacDev\Xamarin.MacDev.csproj">
<Project>{CC3D9353-20C4-467A-8522-A9DED6F0C753}</Project>
<Name>Xamarin.MacDev</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

Просмотреть файл

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.4" targetFramework="net461" />
</packages>

Просмотреть файл

@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.MacDev", "Xamarin.MacDev\Xamarin.MacDev.csproj", "{CC3D9353-20C4-467A-8522-A9DED6F0C753}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "UnitTests\UnitTests.csproj", "{39DBAAF8-57A5-49A3-9E9A-11B545906AED}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -13,5 +15,9 @@ Global
{CC3D9353-20C4-467A-8522-A9DED6F0C753}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC3D9353-20C4-467A-8522-A9DED6F0C753}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{CC3D9353-20C4-467A-8522-A9DED6F0C753}.Release|Any CPU.Build.0 = Debug|Any CPU
{39DBAAF8-57A5-49A3-9E9A-11B545906AED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{39DBAAF8-57A5-49A3-9E9A-11B545906AED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39DBAAF8-57A5-49A3-9E9A-11B545906AED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39DBAAF8-57A5-49A3-9E9A-11B545906AED}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

Разница между файлами не показана из-за своего большого размера Загрузить разницу