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

[Feature Request] key_equal, copy_key, zero_key in dict is slower than direct assignment if key type is primitive #9519

Open
dlee992 opened this issue Apr 1, 2024 · 3 comments · May be fixed by #9520

Comments

@dlee992
Copy link
Contributor

dlee992 commented Apr 1, 2024

Hi, I noticed an unoptimized situation that key_equal, copy_key, zero_key in dict are slower than direct assignment if key type is primitive. The root cause is if key_type doesn't contain meminfo, then key_equal will rollback to using memcmp, which is pretty slow compared to directly this_key == an_integer. Other two functions will rollback to using memcpy, which is also slow.

return memcmp(lhs, rhs, dk->key_size) == 0;

memcpy(dst, src, dk->key_size);

I think we can do more things in this intrinsic function, which includes generation of corresponding functions (i.e., key_equal, copy_key, zero_key) for primitive types. I have already tested this in an internal use-case, this optimization can boost performance at least 5%~10% if using numba typed.dict heavily (i.e., lots of dict lookup, insert operations)

def _dict_set_method_table(typingctx, dp, keyty, valty):

@guilhermeleobas
Copy link
Collaborator

Hi @dlee992, do you have a reproducer for one of the functions you mentioned?

@guilhermeleobas guilhermeleobas added the more info needed This issue needs more information label Apr 1, 2024
@dlee992
Copy link
Contributor Author

dlee992 commented Apr 1, 2024

Hi, @guilhermeleobas.

Sure, I should provide an example to show it, I will give one after I provide a corresponding PR, then we can compare the performance changes with and without this optimization.

But I can ensure this situation is real for heavy usage of numba typed.Dict.

Copy link

github-actions bot commented May 2, 2024

This issue is marked as stale as it has had no activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with any updates and confirm that this issue still needs to be addressed.

@github-actions github-actions bot added the stale Marker label for stale issues. label May 2, 2024
@guilhermeleobas guilhermeleobas added enhancement and removed more info needed This issue needs more information stale Marker label for stale issues. labels May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants