Skip to content

Slow imports #1211

@g0t4

Description

@g0t4

timing

Is it really ok that it takes 209ms to import even a single type from this package?

This feels like the perfect task for Claude Code?!

I have no background in the best way to solve this issue, I just know this feels wrong for such a central dependency. And common, let's be honest, this is a glorified HTTP client.

This destroys downstream performance in packages like langchain_anthropic which wind up taking 300ms+ for imports alone, just to make a simple http call to generate a completion!

python3 -X importtime -c "import anthropic"

...
import time:        66 |      69232 |   anthropic.lib.tools
...
import time:       506 |     116232 |   anthropic.types
...
import time:       329 |     209401 | anthropic
python3 -X importtime -c "from anthropic.types.image_block_param import ImageBlockParam"
...
import time:       313 |     208162 |     anthropic
import time:         7 |     208169 |   anthropic.types
import time:        10 |     208178 | anthropic.types.image_block_param

I'd hate to think that just because it's python it's ok to ignore optimizations... but, perhaps my expectations are miscalibrated, I'm open to that possibility. Am I crazy?

Claude seems to agree

I've got Claude working on some ideas for me! I don't have time to do this myself, but, Claude is killing it with perf profiling and I bet will find the spots we can get some big wins.

Gotta tame the explosion of types and importing all of them on every import basically

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions