Skip to content

Commit

Permalink
fix: group snapshot writes by extension class
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Negin-Ulster committed Nov 30, 2022
1 parent 3325b3c commit 3f762bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/syrupy/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 3f762bb

Please sign in to comment.