ruby-changes:69678
From: Samuel <ko1@a...>
Date: Wed, 10 Nov 2021 15:21:24 +0900 (JST)
Subject: [ruby-changes:69678] 4b89034218 (master): IO::Buffer for scheduler interface.
https://git.ruby-lang.org/ruby.git/commit/?id=4b89034218 From 4b8903421828cb9d4de139180563ae8d8f04e1ab Mon Sep 17 00:00:00 2001 From: Samuel Williams <samuel.williams@o...> Date: Fri, 2 Jul 2021 22:41:16 +1200 Subject: IO::Buffer for scheduler interface. --- NEWS.md | 5 + benchmark/buffer_get.yml | 9 + common.mk | 178 ++++++ doc/fiber.md | 24 +- file.c | 21 +- include/ruby/fiber/scheduler.h | 40 +- include/ruby/internal/intern/file.h | 2 + include/ruby/io.h | 9 + include/ruby/io/buffer.h | 71 +++ inits.c | 1 + io.c | 358 ++++++------ io_buffer.c | 1024 +++++++++++++++++++++++++++++++++++ scheduler.c | 49 +- test/ruby/test_io_buffer.rb | 131 +++++ 14 files changed, 1746 insertions(+), 176 deletions(-) create mode 100644 benchmark/buffer_get.yml create mode 100644 include/ruby/io/buffer.h create mode 100644 io_buffer.c create mode 100644 test/ruby/test_io_buffer.rb diff --git a/NEWS.md b/NEWS.md index 05e2d41eb99..5c2cac23d13 100644 --- a/NEWS.md +++ b/NEWS.md @@ -204,6 +204,9 @@ Outstanding ones only. https://github.com/ruby/ruby/blob/trunk/NEWS.md#L204 * Introduce non-blocking `Timeout.timeout` using `timeout_after` hook. [[Feature #17470]] + * Introduce new scheduler hooks `io_read` and `io_write` along with a + low level `IO::Buffer` for zero-copy read/write. [[Feature #18020]] + * IO hooks `io_wait`, `io_read`, `io_write`, receive the original IO object where possible. [[Bug #18003]] @@ -424,9 +427,11 @@ See [the repository](https://github.com/ruby/error_highlight) in detail. https://github.com/ruby/ruby/blob/trunk/NEWS.md#L427 [Bug #18003]: https://bugs.ruby-lang.org/issues/18003 [Feature #18008]: https://bugs.ruby-lang.org/issues/18008 [Feature #18015]: https://bugs.ruby-lang.org/issues/18015 +[Feature #18020]: https://bugs.ruby-lang.org/issues/18020 [Feature #18029]: https://bugs.ruby-lang.org/issues/18029 [Feature #18172]: https://bugs.ruby-lang.org/issues/18172 [Feature #18229]: https://bugs.ruby-lang.org/issues/18229 [Feature #18290]: https://bugs.ruby-lang.org/issues/18290 [GH-1509]: https://github.com/ruby/ruby/pull/1509 [GH-4815]: https://github.com/ruby/ruby/pull/4815 + diff --git a/benchmark/buffer_get.yml b/benchmark/buffer_get.yml new file mode 100644 index 00000000000..e375dcf85dc --- /dev/null +++ b/benchmark/buffer_get.yml @@ -0,0 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/benchmark/buffer_get.yml#L1 +benchmark: + - name: buffer.get + prelude: buffer = IO::Buffer.new(32, IO::Buffer::MAPPED) + script: buffer.get(:U32, 0) + loop_count: 20000000 + - name: string.unpack + prelude: string = "\0" * 32 + script: string.unpack("C") + loop_count: 20000000 diff --git a/common.mk b/common.mk index 96e452fc6c0..97a9c34b81b 100644 --- a/common.mk +++ b/common.mk @@ -104,6 +104,7 @@ COMMONOBJS = array.$(OBJEXT) \ https://github.com/ruby/ruby/blob/trunk/common.mk#L104 hash.$(OBJEXT) \ inits.$(OBJEXT) \ io.$(OBJEXT) \ + io_buffer.$(OBJEXT) \ iseq.$(OBJEXT) \ load.$(OBJEXT) \ marshal.$(OBJEXT) \ @@ -6972,6 +6973,7 @@ io.$(OBJEXT): {$(VPATH)}internal/xmalloc.h https://github.com/ruby/ruby/blob/trunk/common.mk#L6973 io.$(OBJEXT): {$(VPATH)}io.c io.$(OBJEXT): {$(VPATH)}io.h io.$(OBJEXT): {$(VPATH)}io.rbinc +io.$(OBJEXT): {$(VPATH)}io/buffer.h io.$(OBJEXT): {$(VPATH)}method.h io.$(OBJEXT): {$(VPATH)}missing.h io.$(OBJEXT): {$(VPATH)}node.h @@ -6988,6 +6990,181 @@ io.$(OBJEXT): {$(VPATH)}thread_native.h https://github.com/ruby/ruby/blob/trunk/common.mk#L6990 io.$(OBJEXT): {$(VPATH)}util.h io.$(OBJEXT): {$(VPATH)}vm_core.h io.$(OBJEXT): {$(VPATH)}vm_opts.h +io_buffer.$(OBJEXT): $(hdrdir)/ruby/ruby.h +io_buffer.$(OBJEXT): $(top_srcdir)/internal/bits.h +io_buffer.$(OBJEXT): $(top_srcdir)/internal/compilers.h +io_buffer.$(OBJEXT): $(top_srcdir)/internal/static_assert.h +io_buffer.$(OBJEXT): $(top_srcdir)/internal/string.h +io_buffer.$(OBJEXT): {$(VPATH)}assert.h +io_buffer.$(OBJEXT): {$(VPATH)}backward/2/assume.h +io_buffer.$(OBJEXT): {$(VPATH)}backward/2/attributes.h +io_buffer.$(OBJEXT): {$(VPATH)}backward/2/bool.h +io_buffer.$(OBJEXT): {$(VPATH)}backward/2/gcc_version_since.h +io_buffer.$(OBJEXT): {$(VPATH)}backward/2/inttypes.h +io_buffer.$(OBJEXT): {$(VPATH)}backward/2/limits.h +io_buffer.$(OBJEXT): {$(VPATH)}backward/2/long_long.h +io_buffer.$(OBJEXT): {$(VPATH)}backward/2/stdalign.h +io_buffer.$(OBJEXT): {$(VPATH)}backward/2/stdarg.h +io_buffer.$(OBJEXT): {$(VPATH)}config.h +io_buffer.$(OBJEXT): {$(VPATH)}defines.h +io_buffer.$(OBJEXT): {$(VPATH)}encoding.h +io_buffer.$(OBJEXT): {$(VPATH)}intern.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/anyargs.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic/char.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic/double.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic/fixnum.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic/gid_t.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic/int.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic/intptr_t.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic/long.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic/long_long.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic/mode_t.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic/off_t.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic/pid_t.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic/short.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic/size_t.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic/st_data_t.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/arithmetic/uid_t.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/assume.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/alloc_size.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/artificial.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/cold.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/const.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/constexpr.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/deprecated.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/diagnose_if.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/enum_extensibility.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/error.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/flag_enum.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/forceinline.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/format.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/maybe_unused.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/noalias.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/nodiscard.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/noexcept.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/noinline.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/nonnull.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/noreturn.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/pure.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/restrict.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/returns_nonnull.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/warning.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/attr/weakref.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/cast.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/compiler_is.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/compiler_is/apple.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/compiler_is/clang.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/compiler_is/gcc.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/compiler_is/intel.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/compiler_is/msvc.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/compiler_is/sunpro.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/compiler_since.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/config.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/constant_p.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/core.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/core/rarray.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/core/rbasic.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/core/rbignum.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/core/rclass.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/core/rdata.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/core/rfile.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/core/rhash.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/core/robject.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/core/rregexp.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/core/rstring.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/core/rstruct.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/core/rtypeddata.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/ctype.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/dllexport.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/dosish.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/encoding/coderange.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/encoding/ctype.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/encoding/encoding.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/encoding/pathname.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/encoding/re.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/encoding/sprintf.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/encoding/string.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/encoding/symbol.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/encoding/transcode.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/error.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/eval.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/event.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/fl_type.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/gc.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/glob.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/globals.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/has/attribute.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/has/builtin.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/has/c_attribute.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/has/cpp_attribute.h +io_buffer.$(OBJEXT): {$(VPATH)}internal/has/declspec_attribute.h +io_buffer.$(OBJEXT (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/