Skip to content

C API to create BigDecimal objects #506

@byroot

Description

@byroot

BigDecimal is used by various database clients, as well as various serialization libraries. Many of those are implemented in C, and for them creating BigDecimal objects is an important bottleneck.

For example, here's the relevant code in the Trilogy MySQL client gem: https://github.com/trilogy-libraries/trilogy/blob/7fcfe8c1c79208c6c56439d1d29c7dc591442c53/contrib/ruby/ext/trilogy-ruby/cast.c#L236-L241

It needs to:

  • Allocate a Ruby String and cpy the bytes into it.
  • Use rb_funcall to invoke BigDecimal().

The string allocation isn't too bad, but having to use method dispatch is quite costly.

It would be very useful if there was a set of C APIs to efficiently allocate BigDecimal objects:

VALUE BigDecimal_from_str(const char *, size_t len)`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions