Skip to content

Conversation

Agnik7
Copy link
Contributor

@Agnik7 Agnik7 commented Sep 12, 2023

This PR is with respect to Issue #14298 .

Changes made:

  • Added the UseCFNetworkHandler and UseNSUrlSessionHandler properties.
  • Computed the values for the aforementioned properties.
  • Added two new RuntimeHostConfigurationOption entries.
  • Updated the RuntimeOptions.cs to use the two new Runtime properties.

@Agnik7
Copy link
Contributor Author

Agnik7 commented Sep 12, 2023

@rolfbjarne I have made the changes you requested. Kindly review.

@rolfbjarne
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
Copy link
Member

The changes don't compile:

         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(41,16): error CS1061: 'RuntimeOptions' does not contain a definition for 'UseCFNetworkHandler' and no accessible extension method 'UseCFNetworkHandler' accepting a first argument of type 'RuntimeOptions' could be found (are you missing a using directive or an assembly reference?) [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(41,38): error CS0103: The name '_IsCFNetworkHandlerFeature' does not exist in the current context [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(42,16): error CS1061: 'RuntimeOptions' does not contain a definition for 'UseNSUrlSessionHandler' and no accessible extension method 'UseNSUrlSessionHandler' accepting a first argument of type 'RuntimeOptions' could be found (are you missing a using directive or an assembly reference?) [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(42,41): error CS0103: The name '_IsNSUrlSessionHandlerFeature' does not exist in the current context [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(108,9): error CS0103: The name 'UseCFNetworkHandler' does not exist in the current context [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(109,23): error CS0246: The type or namespace name 'CFNetworkHandler' could not be found (are you missing a using directive or an assembly reference?) [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(112,16): error CS0103: The name 'handler_name' does not exist in the current context [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(112,44): error CS0103: The name 'handler_name' does not exist in the current context [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(113,16): error CS0103: The name 'Runtime' does not exist in the current context [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(113,34): error CS0103: The name 'handler_name' does not exist in the current context [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(114,23): error CS0246: The type or namespace name 'NSUrlSessionHandler' could not be found (are you missing a using directive or an assembly reference?) [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]

did you try to build locally?

@rolfbjarne rolfbjarne added the community Community contribution ❤ label Sep 13, 2023
@vs-mobiletools-engineering-service2

This comment has been minimized.

@Agnik7
Copy link
Contributor Author

Agnik7 commented Sep 13, 2023

The changes don't compile:

         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(41,16): error CS1061: 'RuntimeOptions' does not contain a definition for 'UseCFNetworkHandler' and no accessible extension method 'UseCFNetworkHandler' accepting a first argument of type 'RuntimeOptions' could be found (are you missing a using directive or an assembly reference?) [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(41,38): error CS0103: The name '_IsCFNetworkHandlerFeature' does not exist in the current context [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(42,16): error CS1061: 'RuntimeOptions' does not contain a definition for 'UseNSUrlSessionHandler' and no accessible extension method 'UseNSUrlSessionHandler' accepting a first argument of type 'RuntimeOptions' could be found (are you missing a using directive or an assembly reference?) [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(42,41): error CS0103: The name '_IsNSUrlSessionHandlerFeature' does not exist in the current context [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(108,9): error CS0103: The name 'UseCFNetworkHandler' does not exist in the current context [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(109,23): error CS0246: The type or namespace name 'CFNetworkHandler' could not be found (are you missing a using directive or an assembly reference?) [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(112,16): error CS0103: The name 'handler_name' does not exist in the current context [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(112,44): error CS0103: The name 'handler_name' does not exist in the current context [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(113,16): error CS0103: The name 'Runtime' does not exist in the current context [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(113,34): error CS0103: The name 'handler_name' does not exist in the current context [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]
         /Users/builder/azdo/_work/2/s/xamarin-macios/src/ObjCRuntime/RuntimeOptions.cs(114,23): error CS0246: The type or namespace name 'NSUrlSessionHandler' could not be found (are you missing a using directive or an assembly reference?) [/Users/builder/azdo/_work/2/s/xamarin-macios/tools/dotnet-linker/dotnet-linker.csproj]

did you try to build locally?

@rolfbjarne I wasn't able to build it locally since I have a Windows system, so I just wrote the code. Is it possible for you to build locally and suggest the required changes?

@rolfbjarne
Copy link
Member

@rolfbjarne I wasn't able to build it locally since I have a Windows system, so I just wrote the code. Is it possible for you to build locally and suggest the required changes?

At that point I'll end up doing more work than if I were to do it myself...

To work on this project you really need a Mac to be able to build and test your changes.

@Agnik7
Copy link
Contributor Author

Agnik7 commented Sep 13, 2023

So....what should I do now?? Do you have any ideas?? Really sorry for the inconvinience caused

@dalexsoto
Copy link
Member

@Agnik7 Thank you for your contribution, we are a bit busy right now but we will try to get back to you as soon as possible, as @rolfbjarne mentioned you do need a Mac in order to build this project and do appreciate the intent so give us some time in order to move forward.

@Agnik7
Copy link
Contributor Author

Agnik7 commented Sep 14, 2023

Ok

@github-actions
Copy link
Contributor

⚠️ Your code has been reformatted. ⚠️

If this is not desired, add the actions-disable-autoformat label, and revert the reformatting commit.

If files unrelated to your change were modified, try reverting the reformatting commit + merging with the target branch (and push those changes).

@dalexsoto
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@dustin-wojciechowski
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Windows Integration Tests passed 💻

All Windows Integration Tests passed.

Pipeline on Agent
Hash: 88b97031d8d398cb2b350f72aed36e0eae8922de [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) passed 💻

All tests on macOS M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS M1 - Mac Ventura (13.0) passed 💻

All tests on macOS M1 - Mac Ventura (13.0) passed.

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

📚 [PR Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)
  • iOS (no change detected)
  • tvOS (no change detected)
  • watchOS (no change detected)
  • macOS (no change detected)
NET (empty diffs)
  • iOS: (empty diff detected)
  • tvOS: (empty diff detected)
  • MacCatalyst: (empty diff detected)
  • macOS: (empty diff detected)

✅ API diff vs stable

Legacy Xamarin (No breaking changes)
.NET (No breaking changes)
Legacy Xamarin (stable) vs .NET

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 88b97031d8d398cb2b350f72aed36e0eae8922de [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🚀 [CI Build] Test results 🚀

Test results

✅ All tests passed on VSTS: simulator tests.

🎉 All 232 tests passed 🎉

Tests counts

✅ bcl: All 69 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests: All 1 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 7 tests passed. Html Report (VSDrops) Download
✅ framework: All 8 tests passed. Html Report (VSDrops) Download
✅ generator: All 2 tests passed. Html Report (VSDrops) Download
✅ interdependent_binding_projects: All 7 tests passed. Html Report (VSDrops) Download
✅ install_source: All 1 tests passed. Html Report (VSDrops) Download
✅ introspection: All 8 tests passed. Html Report (VSDrops) Download
✅ linker: All 65 tests passed. Html Report (VSDrops) Download
✅ mac_binding_project: All 1 tests passed. Html Report (VSDrops) Download
✅ mmp: All 2 tests passed. Html Report (VSDrops) Download
✅ mononative: All 6 tests passed. Html Report (VSDrops) Download
✅ monotouch: All 39 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
⚠️ mtouch: No tests selected. Html Report (VSDrops) Download
✅ xammac: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 8 tests passed. Html Report (VSDrops) Download
✅ xtro: All 2 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 88b97031d8d398cb2b350f72aed36e0eae8922de [PR build]

Copy link
Member

@rolfbjarne rolfbjarne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have some numbers to see if the linker really is able to change the app size depending on this behavior.

This can probably be done by editing the size-comparison project here:

https://github.com/xamarin/xamarin-macios/blob/main/tests/dotnet/size-comparison/MySingleView/dotnet/MySingleView.csproj

And check if there's any app size difference between:

  1. No change
  2. Setting UseNativeHttpHandler=false:
<PropertyGroup>
    <UseNativeHttpHandler>false</UseNativeHttpHandler>
</PropertyGroup>
  1. Using NSUrlSessionHandler:
<PropertyGroup>
    <MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
</PropertyGroup>
  1. Using CFNetworkHandler:
<PropertyGroup>
    <MtouchHttpClientHandler>CFNetworkHandler</MtouchHttpClientHandler>
</PropertyGroup>

Then running make compare in the tests/ subdirectory for each case should result in a comparison:

https://github.com/xamarin/xamarin-macios/blob/5f3c312b6ce6eb3cc0011c152bc528de19c806c9/tests/dotnet/Makefile#L17-L18

Comment on lines 157 to +167
internal static RuntimeOptions? Read ()
{
#if NET
var options = new RuntimeOptions ();
if (Runtime.UseCFNetworkHandler)
options.http_message_handler = CFNetworkHandlerValue;
else if (Runtime.UseNSUrlSessionHandler)
options.http_message_handler = NSUrlSessionHandlerValue;

return options;
#else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be simplified a lot more, by inlining this logic in the GetHttpMessageHandler method below:

internal static HttpMessageHandler GetHttpMessageHandler ()
{
#if NET
    if (Runtime.UseCFNetworkHandler)
        return new CFNetworkHandler ();
    if (Runtime.UseNSUrlSessionHandler)
        return new NSUrlSessionHandler ();
    return new HttpClientHandler ();
#else
   // existing logic
#endif
}

Comment on lines +52 to +53
static bool useCFNetworkHandler = false;
static bool useNSUrlSessionHandler = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assignment to the default value is unnecessary, except that the default is to use NSUrlSessionHandler:

Suggested change
static bool useCFNetworkHandler = false;
static bool useNSUrlSessionHandler = false;
static bool useCFNetworkHandler;
static bool useNSUrlSessionHandler = true;

@dustin-wojciechowski dustin-wojciechowski changed the base branch from net8.0 to main November 7, 2023 23:36
Copy link
Contributor

Hi @Agnik7. Due to inactivity, we will close this pull request in 7 days.

2 similar comments
Copy link
Contributor

Hi @Agnik7. Due to inactivity, we will close this pull request in 7 days.

Copy link
Contributor

Hi @Agnik7. Due to inactivity, we will close this pull request in 7 days.

Copy link
Contributor

Hi @Agnik7. This pull request was closed due to inactivity. Please let us know if you'd like to reopen it.

rolfbjarne pushed a commit that referenced this pull request May 20, 2025
Continuation of #19003

This means the linker will remove either `CFNetworkHandler` or `NSUrlSessionHandler` depending on which is chosen at build time (or both, if neither is chosen).

This will shrink app size a little bit, here are the types and members that are no longer included when using `NSUrlSessionHandler`: https://gist.github.com/rolfbjarne/102d77d5f105a7c98ac6be19de725dd5

A very basic app is ~55kb / 0.2% smaller: https://gist.github.com/rolfbjarne/a1cb6898aa560f0a891286be20b9bc3e

Fixes #14298.

---------

Co-authored-by: Agnik Bakshi <[email protected]>
Co-authored-by: Dustin Wojciechowski <[email protected]>
Co-authored-by: Michael Cummings <[email protected]>
Co-authored-by: Alex Soto <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Community contribution ❤
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants