Replace trimmable manifest LINQ XML generation with lightweight XML model#11488
Replace trimmable manifest LINQ XML generation with lightweight XML model#11488Copilot wants to merge 6 commits into
Conversation
Agent-Logs-Url: https://github.com/dotnet/android/sessions/7c90b070-d2df-4124-bea8-b0a5d9070cd1 Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/android/sessions/7c90b070-d2df-4124-bea8-b0a5d9070cd1 Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
|
@copilot build fails: |
Agent-Logs-Url: https://github.com/dotnet/android/sessions/c005d968-85d0-4e7f-bea9-62a5ef0d74c9 Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
... Fixed in e6721fd by aliasing the trimmable manifest model type in |
simonrozsival
left a comment
There was a problem hiding this comment.
@copilot please address these comments
| app.Add (new XElement ("uses-library", | ||
| new XAttribute (AttName, ul.Name), | ||
| new XAttribute (AndroidNs + "required", ul.Required ? "true" : "false"))); | ||
| if (!app.Elements ("uses-library").Any (e => e.AndroidAttribute (ManifestConstants.AttributeName) == ul.Name)) { |
There was a problem hiding this comment.
If we're implementing a new class, we can add helper methods for common operations, such as HasElementWithAndroidAttribute("uses-library", ManifestConstants.AttributeName, ul.Name)
| { | ||
| var existingPermissions = new HashSet<string> ( | ||
| manifest.Elements ("permission").Select (e => (string?)e.Attribute (AttName)).OfType<string> ()); | ||
| manifest.Elements ("permission").Select (e => e.AndroidAttribute (ManifestConstants.AttributeName)).OfType<string> ()); |
There was a problem hiding this comment.
This could be a helper method GetElementAttributeValues("permission", ManifestConstants.AttributeName)
There was a problem hiding this comment.
I'm just wondering if this is actually more efficient than XElement... it would be interesting to see these two implementations in a few BDN microbenchmarks (no need to include them in the PR, just report the difference in performance).
Agent-Logs-Url: https://github.com/dotnet/android/sessions/730ad033-35a2-44fe-8072-0a2e1f387b4b Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Addressed in 9d2e430 by adding |
|
@copilot this added complexity does not justify the very minor perf improvement. I wonder if we really need the read-modify-write flow everywhere and if it cannot be simplified. I think the problem is that we're storing the full XML tree instead of keeping just a well defined subset of the data. |
Agent-Logs-Url: https://github.com/dotnet/android/sessions/59bef1f8-44dc-4e30-a3cc-b0082dd1a6b4 Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Addressed in 22c6763 by simplifying the model so it no longer stores a generic XML node tree: it now keeps only manifest elements and attributes, dropping the text/comment/CDATA node hierarchy. Targeted build and trimmable typemap tests pass. |
The trimmable typemap manifest path used
System.Xml.Linqfor template parsing, read/modify/write merging, rooting, and final output. This PR moves production manifest generation to a purpose-built XML model that stores only the manifest elements and attributes needed by the trimmable pipeline while preserving existing manifest behavior.Manifest model
ManifestDocument/element/attribute model.XmlReader.XmlWriter.Generation pipeline
GenerateTrimmableTypeMap,TrimmableTypeMapGenerator, andGeneratedManifestto passManifestDocumentinstead ofXDocument.Files.CopyIfStreamChanged(...).Manifest merge helpers
XElementmutation to lightweight model mutation.Rooting
Example API shift: