Skip to content

mutmut browse is very slow and uses tons of memory #538

Description

@enkore

With a project this size (i.e. small)

Image

Navigating to one of the larger modules takes a good while with 100% CPU. Memory climbs to around 10 GB RSS. Loading the code diff for a mutant takes a similar amount of time. This all seems really slow to me considering the program doesn't really have to do much.

I think this is because this event handler fires-and-forgets a get_diff_for_mutant thread, and this always seems to reparse the whole mutated module from scratch. In the example above that's ~20 MiB of code parsed per event (the source file is ~80K). This seems logical, the number of mutants doesn't scale linearly.

Parsing the mutant with ast:

33.87user 1.06system 0:35.24elapsed 99%CPU (0avgtext+0avgdata 2020668maxresident)k
40inputs+0outputs (0major+583561minor)pagefaults 0swaps

... and with libcst:

78.86user 4.93system 1:24.50elapsed 99%CPU (0avgtext+0avgdata 9609288maxresident)k
1968inputs+0outputs (1major+2687553minor)pagefaults 0swaps

I think the parsing here is largely unnecessary? When generating the mutants mutmut could store the source spans for each mutant and then reading the mutants would be very cheap. The original and mutated function source can then be parsed to rename the function before generating the diff (or just str.replacing the mutant name).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions