ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: jean.boussier@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:97165] [Ruby master Feature#16029] Expose fstring related APIs to C-extensions
Date: Fri, 14 Feb 2020 14:19:22 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-84271.20200214141922.7941@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16029.20190731010619.7941@ruby-lang.org

Issue #16029 has been updated by byroot (Jean Boussier).


>   it makes sense to add an official API as well that does not depend on dynamic invocation

It's not just about the dynamic invocation. Sure it's a bit slower but not a huge deal.

It's mostly that to get to that invocation you need to first allocate a duplicate string.

The ideal API would allow to pass a char* to avoid all this garbage.

For context our app loads a lot of static data from flat files (json / yaml / messagepack) for a total of over 5M objects (~25% of the allocations during boot). 80% of that ends up deduplicated later on by `String#-@`. 

I believe that if json / psych / messagepack had access to `rb_fstring_cstr`, I could avoid allocating all these useless objects and save a lot of GC time (~30% of our boot time is spent in GC, 25% marking and 5% sweeping).

----------------------------------------
Feature #16029: Expose fstring related APIs to C-extensions
https://bugs.ruby-lang.org/issues/16029#change-84271

* Author: byroot (Jean Boussier)
* Status: Open
* Priority: Normal
----------------------------------------
As discussed with @tenderlove here: https://github.com/ruby/ruby/pull/2287#issuecomment-513865160

We'd like to update various data format parsers (JSON, MessagePack, etc) to add the possibility to deduplicate strings while parsing.

But unfortunately the `rb_fstring_*` family of functions isn't available to C-extensions, so the only available fallback is `rb_funcall(str, rb_intern("-@"))` which most parsers will likely consider too slow. So the various `rb_fstring_*` functions would need to be public.

Proposed patch: https://github.com/ruby/ruby/pull/2299



-- 
https://bugs.ruby-lang.org/

       reply	other threads:[~2020-02-14 14:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-16029.20190731010619.7941@ruby-lang.org>
2020-02-14 14:19 ` jean.boussier [this message]
2020-07-17  9:23 ` [ruby-core:99201] [Ruby master Feature#16029] Expose fstring related APIs to C-extensions eregontp
2020-07-17 10:39 ` [ruby-core:99202] " jean.boussier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-84271.20200214141922.7941@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).