ruby / ruby/bigdecimal

C API to create BigDecimal objects

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

Nobody has claimed this yet.

Dominant language
C
Stars
152
Forks
95
Avg merge
4d 1h
Merged PRs (30d)
10

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)`

Contributor guide

No contributing guide indexed for this repository

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.

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.