Skip to content

Commit

Permalink
[improvement] Removed all usage of reflection, enabled trimming on UW…
Browse files Browse the repository at this point in the history
…P, improved memory usage when compiling .NET Native (#184)

* Removed Android to fix release mode builds

* Removed Android to fix release mode builds

* WIP enabling trimming

* Switched from Newtonsoft to System.Text.Json

* Added more types for app settings serialization

* Enable 64 bit compiler in release mode

* Switched to System.Text.Json + source generators

* Fixed compilation errors from refactor

* Exclude all metadata by default

* Use x64 for PreferredToolArchitecture

* Removed "Prefer32Bit" property

* Revert Microsoft.NETCore.UniversalWindowsPlatform to match MSBuild.Sdk.Extras (6.2.10)

* Updated to .NET 7 preview for Microsoft.CodeAnalysis.NetAnalyzers

* Remove explicit "Excluded" for *Application* runtime directive

* Remove ShortcutGenericAnalysis

* Remove potential infinite loop

* Set the optimizer as single threaded.

* Set the optimizer as single threaded for Release all platforms

* Refactored and cleaned up UWP csproj

* Enabled ShortcutGenericAnalysis in release mode

* Enable generating PDB out of process and bump .NET Native to 6.2.14

* Revert "Enable generating PDB out of process and bump .NET Native to 6.2.14"

This reverts commit 5818a2e.

* Revert "Revert "Enable generating PDB out of process and bump .NET Native to 6.2.14""

This reverts commit 200705c.

Co-authored-by: amaidniazi <[email protected]>
  • Loading branch information
Arlodotexe and amaidniazi authored Jul 22, 2022
1 parent f1383fe commit e7d2fae
Show file tree
Hide file tree
Showing 54 changed files with 648 additions and 845 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="6.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions src/Cores/Files/StrixMusic.Cores.LocalFiles/LocalFilesCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using OwlCore.Extensions;
using StrixMusic.Cores.Files;
using StrixMusic.Cores.Files.Models;
using StrixMusic.Cores.LocalFiles.Services;
using StrixMusic.Cores.LocalFiles.Settings;
using StrixMusic.Sdk.AppModels;
using StrixMusic.Sdk.CoreModels;
using StrixMusic.Sdk.FileMetadata;
Expand Down Expand Up @@ -86,10 +86,10 @@ private void DetachEvents()
/// <summary>
/// The metadata that identifies this core before instantiation.
/// </summary>
public static CoreMetadata Metadata { get; } = new CoreMetadata(id: nameof(LocalFilesCore),
displayName: "Local Files",
logoUri: new Uri("ms-appx:///Assets/Cores/LocalFiles/Logo.svg"),
sdkVer: typeof(ICore).Assembly.GetName().Version);
public static CoreMetadata Metadata { get; } = new CoreMetadata(Id: nameof(LocalFilesCore),
DisplayName: "Local Files",
LogoUri: new Uri("ms-appx:///Assets/Cores/LocalFiles/Logo.svg"),
SdkVer: typeof(ICore).Assembly.GetName().Version);

/// <summary>
/// The settings for this core instance.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using OwlCore.AbstractUI.Models;
using StrixMusic.Cores.LocalFiles.Services;
using StrixMusic.Cores.LocalFiles.Settings;

namespace StrixMusic.Cores.LocalFiles
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.IO;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Diagnostics;
using OwlCore.Services;

namespace StrixMusic.Cores.LocalFiles.Settings
{
/// <summary>
/// An <see cref="IAsyncSerializer{TSerialized}"/> and implementation for serializing and deserializing streams using System.Text.Json.
/// </summary>
public class FilesCoreSettingsSerializer : IAsyncSerializer<Stream>
{
/// <summary>
/// A singleton instance for <see cref="FilesCoreSettingsSerializer"/>.
/// </summary>
public static FilesCoreSettingsSerializer Singleton { get; } = new();

/// <inheritdoc />
public async Task<Stream> SerializeAsync<T>(T data, CancellationToken? cancellationToken = null)
{
var stream = new MemoryStream();
await JsonSerializer.SerializeAsync(stream, data, typeof(T), context: FilesCoreSettingsSerializerContext.Default, cancellationToken: cancellationToken ?? CancellationToken.None);
return stream;
}

/// <inheritdoc />
public async Task<Stream> SerializeAsync(Type inputType, object data, CancellationToken? cancellationToken = null)
{
var stream = new MemoryStream();
await JsonSerializer.SerializeAsync(stream, data, inputType, context: FilesCoreSettingsSerializerContext.Default, cancellationToken: cancellationToken ?? CancellationToken.None);
return stream;
}

/// <inheritdoc />
public async Task<TResult> DeserializeAsync<TResult>(Stream serialized, CancellationToken? cancellationToken = null)
{
var result = await JsonSerializer.DeserializeAsync(serialized, typeof(TResult), FilesCoreSettingsSerializerContext.Default);
Guard.IsNotNull(result);
return (TResult)result;
}

/// <inheritdoc />
public async Task<object> DeserializeAsync(Type returnType, Stream serialized, CancellationToken? cancellationToken = null)
{
var result = await JsonSerializer.DeserializeAsync(serialized, returnType, FilesCoreSettingsSerializerContext.Default);
Guard.IsNotNull(result);
return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Text.Json.Serialization;

namespace StrixMusic.Cores.LocalFiles.Settings
{
/// <summary>
/// Supplies type information for settings values in <see cref="LocalFilesCoreSettings"/>.
/// </summary>
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(bool))]
[JsonSerializable(typeof(string))]
internal partial class FilesCoreSettingsSerializerContext : JsonSerializerContext
{
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using OwlCore.AbstractStorage;
using System.Threading.Tasks;
using System.Threading;
using OwlCore.AbstractStorage;
using OwlCore.Services;
using StrixMusic.Sdk.Services;
using System.Text.Json;

namespace StrixMusic.Cores.LocalFiles.Services
namespace StrixMusic.Cores.LocalFiles.Settings
{
/// <summary>
/// A container for <see cref="LocalFilesCore"/> settings.
Expand All @@ -13,7 +16,7 @@ public sealed class LocalFilesCoreSettings : SettingsBase
/// Creates a new instance of <see cref="LocalFilesCoreSettings"/>.
/// </summary>
public LocalFilesCoreSettings(IFolderData folder)
: base(folder, NewtonsoftStreamSerializer.Singleton)
: base(folder, FilesCoreSettingsSerializer.Singleton)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<ItemGroup>
<PackageReference Include="OwlCore" Version="0.0.71" />
<PackageReference Include="System.Text.Json" Version="6.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Cores/Files/StrixMusic.Cores.OneDrive/OneDriveCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public OneDriveCore(string instanceId, OneDriveCoreSettings settings, IFolderDat
/// <summary>
/// The metadata that identifies this core before instantiation.
/// </summary>
public static CoreMetadata Metadata { get; } = new CoreMetadata(id: nameof(OneDriveCore),
displayName: "OneDrive",
logoUri: new Uri("ms-appx:///Assets/Cores/OneDrive/Logo.svg"),
sdkVer: typeof(ICore).Assembly.GetName().Version);
public static CoreMetadata Metadata { get; } = new CoreMetadata(Id: nameof(OneDriveCore),
DisplayName: "OneDrive",
LogoUri: new Uri("ms-appx:///Assets/Cores/OneDrive/Logo.svg"),
SdkVer: typeof(ICore).Assembly.GetName().Version);
/// <inheritdoc/>
public override string InstanceDescriptor { get; set; } = string.Empty;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.IO;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Diagnostics;
using OwlCore.Services;

namespace StrixMusic.Cores.OneDrive.Services
{
/// <summary>
/// An <see cref="IAsyncSerializer{TSerialized}"/> and implementation for serializing and deserializing streams using System.Text.Json.
/// </summary>
public class FilesCoreSettingsSerializer : IAsyncSerializer<Stream>
{
/// <summary>
/// A singleton instance for <see cref="FilesCoreSettingsSerializer"/>.
/// </summary>
public static FilesCoreSettingsSerializer Singleton { get; } = new();

/// <inheritdoc />
public async Task<Stream> SerializeAsync<T>(T data, CancellationToken? cancellationToken = null)
{
var stream = new MemoryStream();
await JsonSerializer.SerializeAsync(stream, data, typeof(T), context: FilesCoreSettingsSerializerContext.Default, cancellationToken: cancellationToken ?? CancellationToken.None);
return stream;
}

/// <inheritdoc />
public async Task<Stream> SerializeAsync(Type inputType, object data, CancellationToken? cancellationToken = null)
{
var stream = new MemoryStream();
await JsonSerializer.SerializeAsync(stream, data, inputType, context: FilesCoreSettingsSerializerContext.Default, cancellationToken: cancellationToken ?? CancellationToken.None);
return stream;
}

/// <inheritdoc />
public async Task<TResult> DeserializeAsync<TResult>(Stream serialized, CancellationToken? cancellationToken = null)
{
var result = await JsonSerializer.DeserializeAsync(serialized, typeof(TResult), FilesCoreSettingsSerializerContext.Default);
Guard.IsNotNull(result);
return (TResult)result;
}

/// <inheritdoc />
public async Task<object> DeserializeAsync(Type returnType, Stream serialized, CancellationToken? cancellationToken = null)
{
var result = await JsonSerializer.DeserializeAsync(serialized, returnType, FilesCoreSettingsSerializerContext.Default);
Guard.IsNotNull(result);
return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Text.Json.Serialization;

namespace StrixMusic.Cores.OneDrive.Services
{
/// <summary>
/// Supplies type information for settings values in <see cref="LocalFilesCoreSettings"/>.
/// </summary>
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(bool))]
[JsonSerializable(typeof(string))]
internal partial class FilesCoreSettingsSerializerContext : JsonSerializerContext
{
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using OwlCore.AbstractStorage;
using System.Threading.Tasks;
using System.Threading;
using OwlCore.AbstractStorage;
using OwlCore.Services;
using StrixMusic.Sdk.Services;
using System.Text.Json;

namespace StrixMusic.Cores.OneDrive.Services
{
Expand All @@ -13,7 +15,7 @@ public sealed class OneDriveCoreSettings : SettingsBase
/// Creates a new instance of <see cref="OneDriveCoreSettings"/>.
/// </summary>
public OneDriveCoreSettings(IFolderData folder)
: base(folder, NewtonsoftStreamSerializer.Singleton)
: base(folder, FilesCoreSettingsSerializer.Singleton)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<PackageReference Include="Microsoft.Graph" Version="4.14.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.40.0" />
<PackageReference Include="OwlCore" Version="0.0.71" />
<PackageReference Include="System.Text.Json" Version="6.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public async Task InitAsync(CancellationToken cancellationToken = default)

public event EventHandler<string>? InstanceDescriptorChanged;

public CoreMetadata Registration { get; } = new CoreMetadata(id: nameof(MockCore),
displayName: "Mock core",
logoUri: new Uri("https://strixmusic.com/"),
sdkVer: typeof(ICore).Assembly.GetName().Version ?? throw new ArgumentNullException());
public CoreMetadata Registration { get; } = new CoreMetadata(Id: nameof(MockCore),
DisplayName: "Mock core",
LogoUri: new Uri("https://strixmusic.com/"),
SdkVer: typeof(ICore).Assembly.GetName().Version ?? throw new ArgumentNullException());

public string InstanceId { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
<PackageReference Include="OwlCore" Version="0.0.71" />
<PackageReference Include="System.Text.Json" Version="6.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OwlCore" Version="0.0.71" />
<PackageReference Include="System.Text.Json" Version="6.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/Libs/OwlCore.WinUI/OwlCore.WinUI.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="MSBuild.Sdk.Extras/3.0.23">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;monoandroid11.0;uap10.0.19041</TargetFrameworks>
<!--<TargetFrameworks>netstandard2.0;uap10.0.19041</TargetFrameworks>-->
<TargetFrameworks>netstandard2.0;uap10.0.19041</TargetFrameworks>
<!-- Ensures the .xr.xml files are generated in a proper layout folder -->
<GenerateLibraryLayout>true</GenerateLibraryLayout>
<Nullable>enable</Nullable>
Expand All @@ -22,6 +23,7 @@
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls" Version="7.1.2" />
<PackageReference Include="OwlCore" Version="0.0.71" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
<PackageReference Include="System.Text.Json" Version="6.0.5" />
<PackageReference Include="Uno.UI" Version="4.4.5" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'uap10.0.19041'">
Expand Down
19 changes: 0 additions & 19 deletions src/Platforms/StrixMusic.Droid/Assets/AboutAssets.txt

This file was deleted.

Binary file not shown.
41 changes: 0 additions & 41 deletions src/Platforms/StrixMusic.Droid/Main.cs

This file was deleted.

16 changes: 0 additions & 16 deletions src/Platforms/StrixMusic.Droid/MainActivity.cs

This file was deleted.

5 changes: 0 additions & 5 deletions src/Platforms/StrixMusic.Droid/Properties/AndroidManifest.xml

This file was deleted.

Loading

0 comments on commit e7d2fae

Please sign in to comment.