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)`
BigDecimalis used by various database clients, as well as various serialization libraries. Many of those are implemented in C, and for them creatingBigDecimalobjects is an important bottleneck.For example, here's the relevant code in the
TrilogyMySQL client gem: https://github.com/trilogy-libraries/trilogy/blob/7fcfe8c1c79208c6c56439d1d29c7dc591442c53/contrib/ruby/ext/trilogy-ruby/cast.c#L236-L241It needs to:
rb_funcallto invokeBigDecimal().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
BigDecimalobjects: