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

[ENH] __Pyx_PyDict_Pack function (for code size)? #6083

Open
da-woods opened this issue Mar 16, 2024 · 0 comments
Open

[ENH] __Pyx_PyDict_Pack function (for code size)? #6083

da-woods opened this issue Mar 16, 2024 · 0 comments

Comments

@da-woods
Copy link
Contributor

da-woods commented Mar 16, 2024

Is your feature request related to a problem? Please describe.

This'd probably apply mainly to functions with annotations dictionaries. For example

def f(a: int, b: float):
    pass

generates

__pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_a, __pyx_n_s_int) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_b, __pyx_n_s_float) < 0) __PYX_ERR(0, 1, __pyx_L1_error)

which is relatively repetitive (especially for the error handling)

Describe the solution you'd like.

It might be worth creating a __Pyx_PyDict_Pack function for slow code sections that just iterates over variadic arguments to reduce the code size here.

In this case:

__Pyx_PyDict_Pack(2, __pyx_n_s_a, __pyx_n_s_int, __pyx_n_s_b, __pyx_n_s_float)

Describe alternatives you've considered.

The main reason not to do it:

  • the code generated isn't that bad,
  • the dictionary generation code in Cython is already pretty complicated and accounts for lots of different cases. Adding another case looked fairly fiddly to me.

Additional context

I'm listing this as an idea. I'm on the fence if it's likely to be worth it.

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

No branches or pull requests

1 participant