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

Stdlib: Mirror IO_BUFFER_SIZE and UNIX_BUFFER_SIZE in the stdlib and unix lib #13589

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

EruEri
Copy link

@EruEri EruEri commented Nov 3, 2024

#5938

Hi,

I tried to export those value to make it available in Ocaml, but I'm not sure whether the c functions are written in the appropriated files ?

@EruEri EruEri force-pushed the io-unix-buffer-size-stdlib branch from 04ba8da to 8388a24 Compare November 4, 2024 16:11
@OlivierNicole OlivierNicole self-assigned this Nov 13, 2024
@dbuenzli
Copy link
Contributor

dbuenzli commented Jan 7, 2025

Thanks @EruEri for making the ball roll on that one.

I have however one question for upstream. Is it really worth having separate constants for Unix and Sys ?

Shouldn't we simply unify unix and sys to both use IO_BUFFER_SIZE and and simply expose Sys.io_buffer_size ?

Copy link
Contributor

@nojb nojb left a comment

Choose a reason for hiding this comment

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

I have however one question for upstream. Is it really worth having separate constants for Unix and Sys ?

If we believe that the existing API semantics of Unix are unlikely to change substantially in the future (which seems likely), then I guess we could do as suggested.

Incidentally, the constant UNIX_BUFFER_SIZE was initially introduced in d75dd36 and increased to its current value in 1ecb1f4. IO_BUFFER_SIZE was set to its current value in cf1071e.

@damiendoligez: do you have an opinion?

(** Size of the buffer channels

@since 5.4
*)
Copy link
Contributor

Choose a reason for hiding this comment

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

This docstring should be expanded. The whole point of this PR is to document an existing constant to avoid hard-coding values in user programs. Thus, I would expect that the docstring would explain which buffers are concerned, and how is this constant can be used in user programs.

Copy link
Author

@EruEri EruEri Jan 10, 2025

Choose a reason for hiding this comment

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

I honestly don't have a specific example to illustrate the use of those constants.
But like pointed out in the issue, at least those values can be used in the stdlib instead of the hardcoded one.

let chunk_size = 65536 in (* IO_BUFFER_SIZE *)

Copy link
Contributor

Choose a reason for hiding this comment

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

What about “All channels are buffered by default. You may want to perform reads or writes of sizes equal to the buffer size to maximize throughput in certain situations, for instance.”

CAMLprim value caml_unix_io_buffer_size(value unit)
{
return Val_long(UNIX_BUFFER_SIZE);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the constant is the same for both the Unix and Win32 backends, I would expect the definition of the function to be shared. However, I don't see right away a file where it could be put.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants