Skip to content

Performance issue with LoadScopeScheduling when a node has a large number of tests #1212

Open
@yugokato

Description

@yugokato

I've noticed the use of index() in this code block causes a significant performance issue when a node has a large number of tests. This can be improved by precomputing a mapping from node ID to index using a dictionary and look it up in the loop.

eg.

index_map = {nodeid: i for i, nodeid in enumerate(worker_collection)}
nodeids_indexes = [
    index_map[nodeid]
    for nodeid, completed in work_unit.items()
    if not completed
]

To reproduce the issue, you can run pytest -n 2 --dist=loadscope with the following test code:

import pytest

@pytest.mark.parametrize("i", range(100000))
def test_something(i):
    pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions