-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JavaCallableWrappers] avoid
string.Format()
(#1061)
Running PerfView on Windows in a .NET MAUI app, I can see this taking up time inside the `<GenerateJavaStubs/>` MSBuild task: | Name | Inc % | Inc | | --------------------------------------------------------------------------------------------------------------------- | ----: | ----: | | java.interop.tools.javacallablewrappers!Java.Interop.Tools.JavaCallableWrappers.JavaCallableWrapperGenerator..ctor() | 1.4 | 51 | | mscorlib.ni!String.Format | 1.0 | 35 | Around ~26ms appears to be spent inside `JavaCallableWrapperGenerator` calling `string.Format()`. Reviewing the code, there is quite a bit of `WriteLine()` used along with format arguments. I could rework this to use string interpolation, which would be slightly better, as the C# compiler could replace many of these with `string.Concat()`. However, the best case is to just call `Write()` with individual strings, so we don't do extra work creating intermediate string values. Copying `Java.Interop.Tools.JavaCallableWrappers.dll` to: C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.4\tools It appears to save about ~17ms in a `dotnet new maui` project: Top 10 most expensive tasks --GenerateJavaStubs = 795 ms ++GenerateJavaStubs = 812 ms This was an incremental build with a `.xaml` change.
- Loading branch information
1 parent
3a9f770
commit 09f8da2
Showing
1 changed file
with
113 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters