Azure / typespec-azure

About TypeSpec Azure Libraries
https://azure.github.io/typespec-azure/
MIT License
11 stars 37 forks source link

Performance issue with createSDKContext #1172

Open timotheeguerin opened 1 month ago

timotheeguerin commented 1 month ago

Compiling the oracle spec is extrremly slow. After some inital investigation it seems most of it is due to tcgc and the createSDKContext is extremely slow

Adding a timer around took about 10s

    console.time("Create SDK context");
    const tcgcSdkContext = createSdkContext({ program, options: {} }, "@azure-tools/typespec-autorest", {
        versioning: {
            strategy: "ignore",
        },
    });
    console.timeEnd("Create SDK context");
timotheeguerin@Timothees-MacBook-Pro Oracle.Database % tsp compile .
TypeSpec compiler v0.58.0-dev.15

^[ODCreate SDK context: 9.189s
Compilation completed successfully.

In the spec repo cd specification/oracle/Oracle.Database.Management; npx tsp compile .

From issue https://github.com/microsoft/typespec/issues/3845

The createSDKContext should be instant. Tcgc is the combination of 2 things:

  1. Decorators and their accessor
  2. Preprocessor for the dpg emitters

When an emitter(like autorest) that only care about 1. it shouldn't be affected by any of the preprocessing which would slow it down further. The perf here of 10s though is still extremly slow. Openapi3 build does all the parsing, checking, and openapi3 emitting of that spec in 3s

So there is 2 issues to resolve here:

  1. createSDKContext shouldn't be doing anything about the preprocessing used by dpg emitters
  2. In the sdkPackage creation there is an exponential perf drop that needs to be resolved for dpg emitters.
timotheeguerin commented 1 month ago

First issue has been resolved for autorest. Remains that this is not an acceptable performance drop

iscai-msft commented 1 month ago

fixed this issue by exposing createTcgcContext, which the other emitters will load instead

timotheeguerin commented 1 month ago

This solved the fact that it had a bad performance when calling creatSdContect but that bad performance is not expected when you call the preprocessor. This is not urgent anymore to fix but it is still there and might cause really bad build time for larger specs