Skip to content

Conversation

@JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jan 2, 2019

Move some imports that aren't always needed to functions bodies. This
speeds up mypy startup by up to 120ms on my laptop (when not compiled).
Tests are a bit faster as well.

@JukkaL JukkaL requested a review from msullivan January 2, 2019 18:18
Copy link
Collaborator

@msullivan msullivan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love startup speedups!



def get_class_descriptors(cls: 'Type[object]') -> Sequence[str]:
import inspect # Lazy import for minor startup speed win
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What were you timing? I think get_class_descriptors is unfortunately actually on the path for a lot of stuff, even not the daemon, so I suspect this won't speed up real workloads? Though I'm not sure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have been timing mypy --help for this. I timed other changes by type checking a small program. Since this is a very small change I think it's okay to keep it even if it doesn't help in any realistic scenarios.


def write_junit_xml(dt: float, serious: bool, messages: List[str], path: str) -> None:
"""XXX"""
from xml.sax.saxutils import escape
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I thought I had already made this change.

@JukkaL JukkaL merged commit 0560264 into master Jan 3, 2019
@gvanrossum gvanrossum deleted the faster-startup branch January 3, 2019 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants