ty icon indicating copy to clipboard operation
ty copied to clipboard

`discord.py`: Checking `audit_logs.py` takes very long

Open MichaReiser opened this issue 1 month ago • 3 comments

Checking audit_logs.py dominates the entire type-checking time:

  • wall-time: 380ms
  • audit_logs.py: /home/micha/astral/discord.py/discord/audit_logs.py took more than 100ms (340.341158ms)

I haven't looked into what's special about audit_logs.py (or something it imports), that explains its long type-checking time.

There are some other "slow" files but none takes as long as audit_logs.py:

INFO Checking file `/home/micha/astral/discord.py/discord/ext/commands/bot.py` took more than 100ms (104.770849ms)
INFO Checking file `/home/micha/astral/discord.py/discord/client.py` took more than 100ms (121.575732ms)
INFO Checking file `/home/micha/astral/discord.py/discord/http.py` took more than 100ms (117.107697ms)
INFO Checking file `/home/micha/astral/discord.py/discord/guild.py` took more than 100ms (124.385833ms)
INFO Checking file `/home/micha/astral/discord.py/discord/message.py` took more than 100ms (147.963634ms)
INFO Checking file `/home/micha/astral/discord.py/discord/state.py` took more than 100ms (103.881121ms)

MichaReiser avatar Dec 15 '25 11:12 MichaReiser

We can also see this in profiles where most threads finish after 180ms, but then there's one thread that just keeps going

https://share.firefox.dev/3KAw91E

MichaReiser avatar Dec 15 '25 11:12 MichaReiser

We see the same pattern on macos and linux. It's more notable on my Linux machine because it has more cores, but each core has worse single-core performance compared to my mac

MichaReiser avatar Dec 15 '25 11:12 MichaReiser

One thing that stands out to me is that we call is_redundant_with a lot... Like a ton:

  • Total queries executed: 56,481
  • is_redundant_with queries: 42,628
  • Percentage: ~75.5% (42,628 / 56,481)

https://gist.github.com/MichaReiser/0ba51a38663ef7a9de13641a50d1719f

MichaReiser avatar Dec 15 '25 17:12 MichaReiser