Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-72894: Dynamically allocate select fd_sets on Windows based on inputs size#13842

Open
andzn wants to merge 8 commits into
python:mainpython/cpython:mainfrom
andzn:fix-issue-28708andzn/cpython:fix-issue-28708Copy head branch name to clipboard
Open

gh-72894: Dynamically allocate select fd_sets on Windows based on inputs size#13842
andzn wants to merge 8 commits into
python:mainpython/cpython:mainfrom
andzn:fix-issue-28708andzn/cpython:fix-issue-28708Copy head branch name to clipboard

Conversation

@andzn

@andzn andzn commented Jun 5, 2019

Copy link
Copy Markdown

@andzn andzn changed the title bpo-28708: Raise FD_SETSIZE limit to 16384 bpo-28708: Raise FD_SETSIZE limit to 16384 on windows Jun 5, 2019
@asvetlov

asvetlov commented Jun 5, 2019

Copy link
Copy Markdown
Contributor

By this PR you basically increased the memory consumption for every select call from 12 KiB to 384 KiB.
I believe the number is too high.

See the issue's comment added recently

@andzn andzn changed the title bpo-28708: Raise FD_SETSIZE limit to 16384 on windows bpo-28708: Dynamically allocate select fd_sets on Windows based on inputs size Jun 10, 2019

@jdemeyer jdemeyer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To test the new seqsize() code path, I would like to see a test added where select.select() is called with an iterable which is not a tuple or list, for example iter([fd]) instead of [fd].

@jdemeyer jdemeyer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are also missing error checks where you call seqsize().

Comment thread Modules/selectmodule.c Outdated
Comment thread Modules/selectmodule.c Outdated
Comment thread Modules/selectmodule.c
@bedevere-bot

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be put in the comfy chair!

@andzn

andzn commented Jun 14, 2019

Copy link
Copy Markdown
Author

I have made the requested changes; please review again

@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

@asvetlov: please review the changes made to this pull request.

@andzn

andzn commented Jun 14, 2019

Copy link
Copy Markdown
Author

@jdmeyer I removed the seqsize function completely and replaced calls with PySequence_Length.

@NewUserHa

NewUserHa commented Jun 15, 2019

Copy link
Copy Markdown
Contributor

hope this pass soon.
select() limit really is pain ass.

@csabella csabella requested review from asvetlov and jdemeyer January 25, 2020 20:16
@csabella

Copy link
Copy Markdown
Contributor

@andzn, please resolve the merge conflict. Thank you!

@andzn

andzn commented Jan 27, 2020

Copy link
Copy Markdown
Author

@csabella , merge conflicts are now resolved.

@andzn

andzn commented Jul 28, 2020

Copy link
Copy Markdown
Author

@asvetlov, @jdemeyer can you please take a look again at the PR? The requested changes have already been implemented a year ago.

@arhadthedev arhadthedev changed the title bpo-28708: Dynamically allocate select fd_sets on Windows based on inputs size gh-72894: Dynamically allocate select fd_sets on Windows based on inputs size Feb 17, 2023
@arhadthedev arhadthedev added performance Performance or resource usage OS-windows extension-modules C modules in the Modules dir topic-IO labels Feb 17, 2023
@arhadthedev

Copy link
Copy Markdown
Member

@andzn Could you sign the new CLA by clicking not signed button in the cpython-cla-bot's message, please?

@andzn

andzn commented Feb 17, 2023

Copy link
Copy Markdown
Author

@andzn Could you sign the new CLA by clicking not signed button in the cpython-cla-bot's message, please?

@arhadthedev done.

Comment thread Modules/selectmodule.c
do {
if (((fd_set FAR *)(set))->fd_count < setsize)
((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))->fd_count++]=(fd);
} while(0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of the surrounding code do { ... } while (0)?

Comment thread Modules/selectmodule.c
Comment on lines +123 to +124
size_t i;
for (i = 0; i < setsize + 1 && fd2obj[i].sentinel >= 0; i++) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
size_t i;
for (i = 0; i < setsize + 1 && fd2obj[i].sentinel >= 0; i++) {
for (size_t i = 0; i < setsize + 1 && fd2obj[i].sentinel >= 0; i++) {

Comment thread Modules/selectmodule.c
@@ -196,7 +211,7 @@ set2list(fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
return NULL;

i = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you declare i here?

Comment thread Modules/selectmodule.c
int n;
_PyTime_t timeout, deadline = 0;

setsize = FD_SETSIZE;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to initialize the variable where it's declared. Either declare it at this line, or move the declaration here. So the variable is never uninitialized.

Comment thread Modules/selectmodule.c
return NULL;
}

if ((size_t)rsize > setsize) setsize = (size_t)rsize;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may write: setsize = Py_MAX(setsize, (size_t)rsize); (same for the 2 lines below). IMO it's more explicit (and how I would write it in Python).

Comment thread Modules/selectmodule.c
ofdset = (fd_set*) PyMem_NEW(SOCKET, setsize + 1);
efdset = (fd_set*) PyMem_NEW(SOCKET, setsize + 1);
if (ifdset->fd_array == NULL || ofdset->fd_array == NULL || efdset->fd_array == NULL) {
if (ifdset->fd_array) PyMem_DEL(ifdset->fd_array);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyMem_DEL() is a alias to PyMem_Free(): use it directly.

The NULL test is useless and can be removed. PyMem_Free(NULL) is well defined, it does nothing: https://docs.python.org/dev/c-api/memory.html#c.PyMem_Free

Comment thread Modules/selectmodule.c
fd_set *ifdset, *ofdset, *efdset;
#if !defined(MS_WINDOWS)
fd_set ifdset_stack, ofdset_stack, efdset_stack;
#if !defined(SELECT_USES_HEAP)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make the code simpler if the SELECT_USES_HEAP macro would always be defined on Windows, no?

@python python deleted a comment Apr 7, 2025
@github-actions

github-actions Bot commented Mar 4, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting change review extension-modules C modules in the Modules dir OS-windows performance Performance or resource usage stale Stale PR or inactive for long period of time. topic-IO

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.