diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dc9136bb..eae37ba1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -91,6 +91,30 @@ Fill in the relevant sections, clearly linking the issue the change is attemping `debugpy` is installed in local development. A VSCode launch config is provided. Run `inv test -v -d` to enable the debugger (`-d` for debug). It'll then wait for you to attach your VSCode debugging client. +#### Debugging Performance Issues + +You can run `inv benchmark` to run the full benchmark suite. Alternatively, write a test file, e.g.: + +```py +# test_performance.py +import pytest +import os + +SIZE = int(os.environ.get("SIZE", 1000)) + +@pytest.mark.parametrize("x", range(SIZE)) +def test_performance(x, snapshot): + assert x == snapshot +``` + +and then run: + +```sh +SIZE=1000 python -m cProfile -s cumtime -m pytest test_performance.py --snapshot-update -s > profile.log +``` + +See the cProfile docs for metric sorting options. + ## Styleguides ### Commit Messages diff --git a/src/syrupy/session.py b/src/syrupy/session.py index 9f5caf54..51065627 100644 --- a/src/syrupy/session.py +++ b/src/syrupy/session.py @@ -58,9 +58,10 @@ def queue_snapshot_write( data: "SerializedData", index: "SnapshotIndex", ) -> None: - queue = self._queued_snapshot_writes.get(extension, []) + key = hash(extension.__class__) + queue = self._queued_snapshot_writes.get(key, []) queue.append((data, index)) - self._queued_snapshot_writes[extension] = queue + self._queued_snapshot_writes[key] = queue def flush_snapshot_write_queue(self) -> None: for extension, queued_write in self._queued_snapshot_writes.items():