From 94afceaaf29becb5432265dd37bed56d44d0dc4d Mon Sep 17 00:00:00 2001 From: James Hilton-Balfe <50501825+Gobot1234@users.noreply.github.com> Date: Wed, 29 Dec 2021 23:00:50 +0000 Subject: [PATCH 1/3] Cache things more --- .github/workflows/perf.yml | 50 +++++++++++++++++++++++++++++++++++++ src/betterproto/__init__.py | 12 +++++---- 2 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/perf.yml diff --git a/.github/workflows/perf.yml b/.github/workflows/perf.yml new file mode 100644 index 000000000..e7911beaa --- /dev/null +++ b/.github/workflows/perf.yml @@ -0,0 +1,50 @@ +name: Run Performance tests + +on: [pull_request] + +jobs: + bench: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + + - name: Get full Python version + id: full-python-version + shell: bash + run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))") + + - name: Install poetry + shell: bash + run: | + python -m pip install poetry + echo "$HOME/.poetry/bin" >> $GITHUB_PATH + + - name: Configure poetry + shell: bash + run: poetry config virtualenvs.in-project true + + - name: Set up cache + uses: actions/cache@v2 + id: cache + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }} + + - name: Ensure cache is healthy + if: steps.cache.outputs.cache-hit == 'true' + shell: bash + run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv + + - name: Install dependencies + shell: bash + run: | + poetry run python -m pip install pip -U + poetry install + + - name: Run benchmarks + run: + poetry run python -m asv continuous master HEAD diff --git a/src/betterproto/__init__.py b/src/betterproto/__init__.py index 3cee8887e..f562b664c 100644 --- a/src/betterproto/__init__.py +++ b/src/betterproto/__init__.py @@ -724,11 +724,13 @@ def _betterproto(self) -> ProtoClassMetadata: It may be initialized multiple times in a multi-threaded environment, but that won't affect the correctness. """ - meta = getattr(self.__class__, "_betterproto_meta", None) - if not meta: + cls = self.__class__ + try: + return cls._betterproto_meta + except AttributeError: meta = ProtoClassMetadata(self.__class__) - self.__class__._betterproto_meta = meta # type: ignore - return meta + cls._betterproto_meta = meta # type: ignore + return meta def __bytes__(self) -> bytes: """ @@ -846,7 +848,7 @@ def _type_hint(cls, field_name: str) -> Type: @classmethod def _type_hints(cls) -> Dict[str, Type]: module = sys.modules[cls.__module__] - return get_type_hints(cls, vars(module)) + return get_type_hints(cls, module.__dict__, {}) @classmethod def _cls_for(cls, field: dataclasses.Field, index: int = 0) -> Type: From 64878654f6dfc94c3322b772073a8048ca63fb3b Mon Sep 17 00:00:00 2001 From: James Hilton-Balfe <50501825+Gobot1234@users.noreply.github.com> Date: Thu, 30 Dec 2021 00:07:54 +0000 Subject: [PATCH 2/3] Use HEAD as branch --- .github/workflows/perf.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/perf.yml b/.github/workflows/perf.yml index e7911beaa..83df3bd99 100644 --- a/.github/workflows/perf.yml +++ b/.github/workflows/perf.yml @@ -47,4 +47,4 @@ jobs: - name: Run benchmarks run: - poetry run python -m asv continuous master HEAD + poetry run python -m asv continuous HEAD From 8daf51982e367fd768ac8f1ec0cd29d43ffac3ba Mon Sep 17 00:00:00 2001 From: James Hilton-Balfe <50501825+Gobot1234@users.noreply.github.com> Date: Thu, 30 Dec 2021 00:10:36 +0000 Subject: [PATCH 3/3] Use github.ref as branch? --- .github/workflows/perf.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/perf.yml b/.github/workflows/perf.yml index 83df3bd99..30ac5570c 100644 --- a/.github/workflows/perf.yml +++ b/.github/workflows/perf.yml @@ -47,4 +47,4 @@ jobs: - name: Run benchmarks run: - poetry run python -m asv continuous HEAD + poetry run python -m asv continuous master ${{ github.ref }}