Skip to content

Lack of PGO probes in instrumented builds of libcoreclr #124141

Closed

Description

@hoyosjs

When building coreclr with --pgoinstrument, libcoreclr.so ends up with essentially no PGO instrumentation probes. The add_pgo(coreclr) call in src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt uses target_compile_options(PRIVATE), which only applies -flto -fprofile-instr-generate to the source files compiled directly into the coreclr shared library target - just mscoree.cpp and exports.cpp. The resulting library has very few probes (20-100 over ~30 functions). The vast majority of the runtime code lives in static libraries (cee_wks, utilcode, coreclrpal, etc.) that are linked in already compiled, without instrumentation flags. This doesn't affect clrjit because the JIT compiles all its source files directly into the shared library target. Windows doesn't have this issue since this is a link time option.

Activity

  1. added
    untriaged
    on Feb 8, 2026
  2. added
    needs-area-label
    on Feb 8, 2026
  3. hoyosjs commented on Feb 8, 2026

    @hoyosjs
    MemberAuthor

    Possible fix 1 (and I'd go a step further of cleanup and just move it to configure compiler at that point) is to define the compilation option globally

    Possible fix 2 - walk the graph of deps when an add_pgo target is specified.

    Both are in https://github.com/hoyosjs/runtime/commits/juhoyosa/fix-pgo

    Fix 2 preserves behavior, but i'm not sure this complexity is buying us much. These builds mostly just get used for training and picking partial sets is not something I think gives us any benefit. After change 1, I see coreclr having ~5.1k probes. With the second, I see it have around 4.7k.

  4. added
    area-Infrastructure-coreclr
    and removed
    needs-area-label
    on Feb 8, 2026
  5. dotnet-policy-service commented on Feb 8, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @agocke, @dotnet/runtime-infrastructure
    See info in area-owners.md if you want to be subscribed.

  6. steveisok commented on Feb 8, 2026

    @steveisok
    Member

    Fix 2 preserves behavior, but i'm not sure this complexity is buying us much. These builds mostly just get used for training and picking partial sets is not something I think gives us any benefit. After change 1, I see coreclr having ~5.1k probes. With the second, I see it have around 4.7k.

    Push what you think is best and have us react there.

  7. jkotas commented on Feb 8, 2026

    @jkotas
    Member

    Possible fix 1 (and I'd go a step further of cleanup and just move it to configure compiler at that point) is to define the compilation option globally

    I think this is the right option.

    Ideally, we would get the PGO data for all native binaries that we ship, including e.g. System.Compression.Native.so.

  8. EgorBo commented on Feb 9, 2026

    @EgorBo
    Member

    Some time ago I tried to do that via #67820

  9. AndyAyersMS commented on Feb 11, 2026

    @AndyAyersMS
    Member

    @davidwrighton I wonder if this contributes to the TP issues you see in #123830, maybe the newly split off files no longer get handled via -flto? It seems odd in your PR the TP is so much worse on Linux than Windows.

  10. added and removed
    area-Infrastructure-coreclr
    on Apr 13, 2026
  11. dotnet-policy-service commented on Apr 13, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/runtime-infrastructure
    See info in area-owners.md if you want to be subscribed.

  12. 3 remaining items

  13. added
    untriaged
    and removed
    untriaged
    on Jun 25, 2026
  14. EgorBo commented on Jun 25, 2026

    @EgorBo
    Member

    Let's keep it open till we get a confirmation libcoreclr is optimized with PGO

  15. removed
    untriaged
    on Jul 8, 2026
  16. added this to the 11.0.0 milestone on Jul 8, 2026
  17. added
    Priority:1
    on Jul 10, 2026
  18. hoyosjs commented on Jul 13, 2026

    @hoyosjs
    MemberAuthor

    This is currently stuck - dotnet pgo crashes on arm64 during training

  19. EgorBo commented on Jul 13, 2026

    @EgorBo
    Member

    This is currently stuck - dotnet pgo crashes on arm64 during training

    @hoyosjs do you mean because of #128412 or for unknown reasons?

  20. hoyosjs commented on Jul 13, 2026

    @hoyosjs
    MemberAuthor

    I don't think it's related - but it's blocking training. So we never got data.

  21. added a commit that references this issue on Jul 15, 2026
    de10b65
  22. hoyosjs commented on Aug 6, 2026

    @hoyosjs
    MemberAuthor

    On linux x64:

    Instrumentation level: Front-end
    Total functions: 23033
    Maximum function count: 371612116
    Maximum internal block count: 310247889
    Total number of blocks: 157560
    Total count: 12753922631
    Detailed summary:
    1 blocks (0.00%) with count >= 371612116 account for 1% of the total counts.
    4 blocks (0.00%) with count >= 283031649 account for 10% of the total counts.
    44 blocks (0.03%) with count >= 17350575 account for 20% of the total counts.
    146 blocks (0.09%) with count >= 10104082 account for 30% of the total counts.
    310 blocks (0.20%) with count >= 6280439 account for 40% of the total counts.
    570 blocks (0.36%) with count >= 3914974 account for 50% of the total counts.
    990 blocks (0.63%) with count >= 2400265 account for 60% of the total counts.
    1670 blocks (1.06%) with count >= 1463177 account for 70% of the total counts.
    2939 blocks (1.87%) with count >= 693433 account for 80% of the total counts.
    5766 blocks (3.66%) with count >= 276788 account for 90% of the total counts.
    8997 blocks (5.71%) with count >= 133669 account for 95% of the total counts.
    16800 blocks (10.66%) with count >= 24530 account for 99% of the total counts.
    29359 blocks (18.63%) with count >= 2433 account for 99.9% of the total counts.
    41190 blocks (26.14%) with count >= 265 account for 99.99% of the total counts.
    50914 blocks (32.31%) with count >= 33 account for 99.999% of the total counts.
    57816 blocks (36.69%) with count >= 7 account for 99.9999% of the total counts.
    Binary IDs:
    064dc193433b7a0a271535254baa81e2ba5afdf5
    9ed95c5818bafa52e1d3f61b93b3a88d814c9246
    
  23. hoyosjs commented on Aug 6, 2026

    @hoyosjs
    MemberAuthor

    triggered #131916 that is the first one to bring these:

    cc: @jkotas @AndyAyersMS @EgorBo

  24. locked and limited conversation to collaborators on Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Priority:1area-Infrastructure

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions