Made resources index binary #9949
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does the pull request do?
This PR changes the Avalonia resources index to a simple binary format that can be read/written using only
BinaryReader/Writer, instead of relying onSystem.Xml.Linqfor reading andDataContractfor writing. Note that the previous index wasn't pure XML: it contained a binary version header.Since all XAML files are compiled to IL, this was the last piece of code to reference
System.Xmlat runtime. After this PR, there's no more dependencies on it and it can be trimmed. A XAML-based framework that doesn't requireSystem.Xml!A self-contained hello world app published trimmed for win10-x64 results in 20 (!!) fewer published assemblies, and a 2.2 MB size reduction. (I wasn't expecting so much; it turns out that even trimmed,
System.Xmlhas a lot of dependencies.)Removed assemblies:
On my PC, this also save ≈10ms of JIT time at startup.
Breaking changes
This is a breaking change since the resources index format has changed. All Avalonia resources need to be recompiled.
Note to devs: if this PR merged, you might need to delete your
objfolders manually to force the new format to be used due to cached resource files. See #9948 (even if that other PR is merged, any build made before it might contain stale resources). NuGet consumers shouldn't be affected by this cache issue since the package version will be different.Misc notes
AvaloniaResourcesIndexReaderWriter.Createwith a slightly more genericWriteResourcesmethod, used to write a full resources file (size + index + resources), to avoid duplicated code in the build tasks.Platform\Internal\Constants.csfile to the build tasks project and replaced the!AvaloniaResourcesby the existing constant.DataContractfile generated by the build tasks and included in the resources:!AvaloniaResourceXamlInfo. However, it doesn't seem to be read anywhere at runtime so it doesn't really matter. Is this file a leftover from a previous implementation that can be removed?