GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Typing: Document performance pitfalls of protocols decorated with `@runtime_checkable` · Issue #102936 · python/cpython

Typing: Document performance pitfalls of protocols decorated with @runtime_checkable #102936

New issue
Copy link
New issue
Copy link
Closed
Closed
Typing: Document performance pitfalls of protocols decorated with @runtime_checkable#102936
Copy link
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirtopic-typing

Description

@AlexWaygood
AlexWaygood
opened on Mar 22, 2023
Issue body actions

Documentation

The following two calls look similar, but the second is dramatically slow compared to the first:

from typing import SupportsInt

isinstance(3, int)
isinstance(3, SupportsInt)

The reason for the slowness is because of _ProtocolMeta.__instancecheck__, which makes calling isinstance() against any runtime-checkable protocol pretty slow. It's possible we can find ways of optimising _ProtocolMeta.__instancecheck__, but whatever we do, it is likely to remain substantially slower to call isinstance() against runtime-checkable protocols than it is to call isinstance() against "normal" classes. This is often pretty surprising for users, so one of the consensus points in python/typing#1363 was that this should be better documented.

Linked PRs

  • gh-102936: typing: document performance pitfalls of protocols decorated with @runtime_checkable #102937
  • [3.11] gh-102936: typing: document performance pitfalls of protocols decorated with @runtime_checkable (GH-102937) #102963
  • [3.10] gh-102936: typing: document performance pitfalls of protocols decorated with @runtime_checkable (GH-102937) #102964

Activity

  1. AlexWaygood
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    topic-typing
    on Mar 22, 2023
  2. AlexWaygood
    added a commit that references this issue on Mar 23, 2023

    gh-102936: typing: document performance pitfalls of protocols decorat…

    58d2b30
  3. miss-islington
    added 4 commits that reference this issue on Mar 23, 2023

    pythongh-102936: typing: document performance pitfalls of protocols d…

    924e20e

    pythongh-102936: typing: document performance pitfalls of protocols d…

    8cd301d

    gh-102936: typing: document performance pitfalls of protocols decorat…

    e2924c0

    gh-102936: typing: document performance pitfalls of protocols decorat…

    6c667d0
  4. AlexWaygood
    closed this as completedon Mar 23, 2023
  5. Fidget-Spinner
    added a commit that references this issue on Mar 27, 2023

    pythongh-102936: typing: document performance pitfalls of protocols d…

    10b47a8
  6. warsaw
    added a commit that references this issue on Apr 11, 2023

    pythongh-102936: typing: document performance pitfalls of protocols d…

    0933b35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirDocumentation in the Doc dirtopic-typing

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.