Skip to content
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

Function dispatcher optimization #227

Merged
merged 2 commits into from
Jun 3, 2023
Merged

Function dispatcher optimization #227

merged 2 commits into from
Jun 3, 2023

Conversation

wjakob
Copy link
Owner

@wjakob wjakob commented Jun 3, 2023

This commit simplifies and optimizes the performance-critical function dispatch loop (both simple + complex variants).

Besides dispatching calls, this loop code previously did a few additional things that are now all moved to other places:

  • Ensuring that an already initialized class cannot be initialized again. The class type caster now checks for this.

  • Ensuring sure that super().function() within a trampoline reaches the parent class implementation of function(), which required tracking some TLS state. This functionality moved to the trampoline-specific implementation in nb_trampoline.cpp / trampoline.h.

  • Double-checking that the 'self' type in a constructor is actually a class bound via nanobind. nanobind now verifies that this is the case when the binding is first created.

  • Besides function dispatcher tweaks, there is also a small improvement related to trampolines: dispatching a function call to Python now acquires/releases the GIL only a single time instead of twice.

  • The commit adds a bit to nb_inst and hence bumps the ABI version.

@wjakob wjakob force-pushed the dispatcher-optim branch from fb1d193 to fb7d101 Compare June 3, 2023 12:32
wjakob added 2 commits June 3, 2023 14:36
This commit simplifies and optimizes the performance-critical function
dispatch loop (both simple + complex variants).

Besides dispatching calls, this loop code previously did a few
additional things that are now all moved to other places:

- Ensuring that an already initialized class cannot be initialized
  again. The class type caster now checks for this.

- Ensuring sure that ``super().function()`` within a trampoline reaches the
  parent class implementation of ``function()``, which required tracking
  some TLS state. This functionality is now moved to the trampolines.

- Double-checking that the 'self' type in a constructor is actually a
  class bound via nanobind. nanobind now verifies that this is the case
  when the binding is first created.

- Besides function dispatcher tweaks, there is also a small improvement
  related to trampolines: dispatching a function call to Python now
  acquires/releases the GIL only a single time instead of twice.

- The commit adds a bit to ``nb_inst`` and hence bumps the ABI version.
@wjakob wjakob force-pushed the dispatcher-optim branch from fb7d101 to 99668e1 Compare June 3, 2023 12:36
@wjakob wjakob merged commit 188dd5d into master Jun 3, 2023
@wjakob wjakob deleted the dispatcher-optim branch June 3, 2023 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant