Skip to content

[python-package] remove unnecessary allocations in ctypes code#6111

Merged
jameslamb merged 1 commit intomasterfrom
unnecessary-lists
Sep 25, 2023
Merged

[python-package] remove unnecessary allocations in ctypes code#6111
jameslamb merged 1 commit intomasterfrom
unnecessary-lists

Conversation

@jameslamb
Copy link
Collaborator

A few places in the Python package use a pattern like the following:

ctypes.c_char_p(*[ctypes.addressof(string_buffer)])

That's identical to the following ...

ctypes.c_char_p(ctypes.addressof(string_buffer))

... except that it involves allocating, unpacking, and then immediately freeing a list object.

This PR proposes removing those unnecessary allocations, to make those code paths slightly faster and reduce their memory usage a tiny bit.

Notes for reviewers

Docs on ctypes.c_char_p() accepting a memory address as an int: https://docs.python.org/3/library/ctypes.html#ctypes.c_char_p

@jameslamb jameslamb merged commit 60a4a13 into master Sep 25, 2023
@jameslamb jameslamb deleted the unnecessary-lists branch September 25, 2023 15:50
@github-actions
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants