-
-
Notifications
You must be signed in to change notification settings - Fork 65
Performance optimizations #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
43e4d49
Refactor OperationIndex to reducee nubmer of database transactions
droserasprout 320e396
Some docs
droserasprout 762c545
Do the same for BigMapIndex
droserasprout 0c3b535
Docs
droserasprout 70b7522
Changelog
droserasprout 869a3b3
Fix index state not being updated
droserasprout 35629c2
Merge branch 'master' into ref/less-db-transactions
droserasprout 53ef574
Refactor index module
droserasprout f14f162
Fix fire_handler calls
droserasprout a762d63
Merge branch 'master' into ref/less-db-transactions
droserasprout 9414f8a
Fix changelog
droserasprout 54abace
Lint
droserasprout 8daf75f
`LazyOperationFetcher` helper 🤔
droserasprout 01093a9
Test utils index matcher benchmark
droserasprout File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| cp tests/benchmarks/config.latest.json tests/benchmarks/config.json | ||
| cp tests/benchmarks/config.latest.json tests/benchmarks/config.json | ||
| cp tests/benchmarks/index.latest.json tests/benchmarks/index.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| rm tests/benchmarks/config.latest.json | ||
| python tests/benchmarks/config.py -o tests/benchmarks/config.latest.json | ||
| python -m pyperf compare_to --table tests/benchmarks/config.json tests/benchmarks/config.latest.json | ||
| for i in config index; do | ||
| rm tests/benchmarks/$i.latest.json; | ||
| python tests/benchmarks/$i.py -o tests/benchmarks/$i.latest.json; | ||
| python -m pyperf compare_to --table tests/benchmarks/$i.json tests/benchmarks/$i.latest.json; | ||
| done; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import logging | ||
| from collections import deque | ||
| from contextlib import contextmanager | ||
| from typing import AsyncGenerator, Deque, Iterator, Tuple | ||
| from unittest.mock import patch | ||
|
|
||
| from dipdup.datasources.tzkt.datasource import OperationFetcher | ||
| from dipdup.index import OperationIndex | ||
| from dipdup.models import OperationData | ||
|
|
||
| logging.basicConfig(level=logging.ERROR) | ||
|
|
||
|
|
||
| # NOTE: Not an actual fuzzer :) | ||
| class OperationFetcherFuzzer(OperationFetcher): | ||
| """This thing is lazy, so instead of fetching all operations it returns the same data over and over again.""" | ||
|
|
||
| levels: int | ||
| repeats: int | ||
|
|
||
| def __new__(cls, *a, **kw): | ||
| super().__new__(cls, *a, **kw) | ||
| cls.levels = 100 | ||
| cls.repeats = 100 | ||
|
|
||
| async def fetch_operations_by_level(self) -> AsyncGenerator[Tuple[int, Tuple[OperationData, ...]], None]: | ||
| self._datasource._http._config.batch_size = 1000 | ||
| level_operations: Deque[Tuple[int, Tuple[OperationData, ...]]] = deque() | ||
| async for level, operations in super().fetch_operations_by_level(): | ||
| level_operations.append((level, operations)) | ||
| if len(level_operations) >= self.levels: | ||
| break | ||
|
|
||
| for _ in range(self.repeats): | ||
| for level, operations in level_operations: | ||
| yield level, operations | ||
|
|
||
|
|
||
| class OperationIndexFuzzer(OperationIndex): | ||
| async def _process_level_operations(self, operations: Tuple[OperationData, ...]) -> None: | ||
| await self._match_operations(operations) | ||
|
|
||
|
|
||
| @contextmanager | ||
| def with_operation_fetcher_fuzzer(levels=100, repeats=100) -> Iterator[None]: | ||
| OperationFetcherFuzzer.levels = levels | ||
| OperationFetcherFuzzer.repeats = repeats | ||
| with patch('dipdup.datasources.tzkt.datasource.OperationFetcher', OperationFetcherFuzzer): | ||
| yield | ||
|
|
||
|
|
||
| @contextmanager | ||
| def with_operation_index_fuzzer(levels=100, repeats=100) -> Iterator[None]: | ||
| with with_operation_fetcher_fuzzer(levels=levels, repeats=repeats): | ||
| with patch('dipdup.index.OperationIndex', OperationIndexFuzzer): | ||
| yield | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import asyncio | ||
droserasprout marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| from contextlib import suppress | ||
| from os.path import dirname, join | ||
|
|
||
| import pyperf # type: ignore | ||
|
|
||
| from dipdup.config import DipDupConfig | ||
| from dipdup.dipdup import DipDup | ||
| from dipdup.exceptions import ReindexingRequiredError | ||
| from dipdup.test import with_operation_index_fuzzer | ||
|
|
||
|
|
||
| def add_cmdline_args(cmd, args): | ||
| cmd += ['--quiet'] | ||
|
|
||
|
|
||
| runner = pyperf.Runner(add_cmdline_args=add_cmdline_args) | ||
|
|
||
|
|
||
| paths = [ | ||
| join(dirname(__file__), '..', 'integration_tests', name) | ||
| for name in [ | ||
| 'hic_et_nunc.yml', | ||
| ] | ||
| ] | ||
|
|
||
|
|
||
| async def _match(): | ||
| for path in paths: | ||
| config = DipDupConfig.load([path]) | ||
| config.database.path = ':memory:' | ||
| config.initialize() | ||
|
|
||
| with with_operation_index_fuzzer(10, 3): | ||
| dipdup = DipDup(config) | ||
| with suppress(ReindexingRequiredError): | ||
| await dipdup.run(True, True) | ||
|
|
||
|
|
||
| runner.bench_func('index_match_operations', lambda: asyncio.run(_match())) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.