microsoftgraph / msgraph-sdk-go

Microsoft Graph SDK for Go
https://docs.microsoft.com/en-us/graph/sdks/sdks-overview
MIT License
232 stars 34 forks source link

Issue with the size of the API surface of the models package #129

Closed breml closed 1 year ago

breml commented 2 years ago

The way, this Go module and especially the models package are constructed, leads to severe issues with the go tooling (and linting).

We have a simple Go application where we added the functionality to send email notifications though the Microsoft Graph API using Mail.Send. So we added the necessary packages, namely:

import (
    "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
    authentication "github.com/microsoft/kiota-authentication-azure-go"
    msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
    "github.com/microsoftgraph/msgraph-sdk-go/me/sendmail"
    "github.com/microsoftgraph/msgraph-sdk-go/models"
)

for this purpose.

The final code did what was expected (sending the mail), but it also made the duration for go test to jump from 7s to 8m 50s and the linting with golangci-lint to jump from 36s to 7m 13s in our Github Action pipeline.

We then changed the Graph API request to a "plain HTTP Post request" using the net/http package from the standard library (while still using github.com/Azure/azure-sdk-for-go/sdk/azidentity and github.com/microsoft/kiota-authentication-azure-go for the authentication) and we are back at the normal times for tests and linting.

Additional pointers for the excessive size of the github.com/microsoftgraph/msgraph-sdk-go/models package are the official documentation refuses to display the API because it is too large and also Github only shows the first 1000 files when listing the content of said package folder.

So in my opinion, the API surface of the package github.com/microsoftgraph/msgraph-sdk-go/models is way to broad and this should be refactored massively.

stephenwan-opal commented 1 year ago

Sorry 55 in case of beta

Sorry, I misspoke in my previous comment. These results are with the v0.55.0 beta release. Here's my upgrade diff:

-  github.com/microsoft/kiota-abstractions-go v0.15.1
-  github.com/microsoft/kiota-authentication-azure-go v0.5.0
-  github.com/microsoft/kiota-serialization-json-go v0.7.2
-  github.com/microsoftgraph/msgraph-beta-sdk-go v0.50.0
-  github.com/microsoftgraph/msgraph-sdk-go-core v0.31.0
+  github.com/microsoft/kiota-abstractions-go v0.17.2
+  github.com/microsoft/kiota-authentication-azure-go v0.6.0
+  github.com/microsoft/kiota-serialization-json-go v0.8.2
+  github.com/microsoftgraph/msgraph-beta-sdk-go v0.55.0
+  github.com/microsoftgraph/msgraph-sdk-go-core v0.34.1
swenson commented 9 months ago

Hi,

We've noticed this is still an issue today. Specifically, the msgraph-sdk-go dependency adds approximately 92 MiB to our binary size, 27 MiB of which is in the executable code itself (all on darwin/arm64). This is a problem because there is effectively a 128 MiB limit on executable code on ARM64, so 21% of the entire code budget is used by this one dependency.

We'd love if there was a supported way to generate a subset of APIs, or to generate this API in such a way that the compiler could more effectively remove the pieces we aren't using (e.g., by more effectively modularizing the API).

baywet commented 9 months ago

@swenson checkout kiota the generator behind this SDK which also allows you to select only the path segments/operations you need, drastically reducing the binary size.