C API to create BigDecimal objects

Open
#506 4 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
c, ruby
Domain
api

Research direction

Start with the linked Trilogy contrib/ruby/ext/trilogy-ruby/cast.c conversion code at lines 236-241 and trace how it currently creates BigDecimal values. The requested API should accept a byte string and length; done means C clients can create BigDecimal objects without allocating an intermediate Ruby String or calling BigDecimal through rb_funcall.

Written by the indexing model from the issue text.

Description

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)`
Dominant language
C
Stars
152
Forks
99
Avg merge
3d 3h
Merged PRs (30d)
5

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby/bigdecimal

All issues in ruby/bigdecimal

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.