Skip to content

Faster set creation with generator expression #771

Closed
@JukkaL

Description

@JukkaL

Currently set(f(x) for x in it) is slower than {f(x) for x in it}, since the first one is evaluated like this:

set([f(x) for x in it])  # Note extra [...]!

We create a needless temporary list, which adds overhead.

It would be better to generate similar code for both alternatives.

For extra credit, do a similar optimization for other suitable candidates that are
handled by mypyc.irbuild.specialize.translate_safe_generator_call.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions