* The future of Ruby bindings
@ 2021-04-30 22:14 Felipe Contreras
2021-05-08 6:28 ` Felipe Contreras
0 siblings, 1 reply; 2+ messages in thread
From: Felipe Contreras @ 2021-04-30 22:14 UTC (permalink / raw)
To: notmuch; +Cc: Ali Polatel
Hi,
Ruby is by far my favorite programming language, and I'm very familiar
with the way it's meant to be used.
This is very idiomatic of Ruby:
$db.query('').search_threads.each do |thread|
puts thread.subject
end
It works perfectly fine, but it leaks memory.
In order to prevent memory from being leaked, we have to do something
like:
query = $db.query('')
threads = query.search_threads
threads.each do |thread|
puts thread.subject
thread.destroy!
end
threads.destroy!
query.destroy!
This is very ugly Ruby.
Ruby is a garbage collected language, this destroy! approach works, but
there's no better way to describe it but "a hack".
I understand why Ali Polatel did commit c7893408 (ruby: Kill garbage
collection related cruft., 2010-05-26); because the order of the object
destruction cannot be ensured in Ruby, however, there's ways to
workaround that.
1. We can steal the object
2. We can increase the reference count
3. We can add a second parent
The notmuch API doesn't have helpers to do either one of those things,
but since we know talloc is used internally, we can simply utilize that
knowledge.
I sent a proof of concept patch [1], that uses method 3, but it was
ignored.
I could proceed and do the actual full patch using this method over all
the Ruby code, but it's tedious work that I would rather not do until I
know such an approach would be accepted.
With my proposed approach we wouldn't have to rely on destroy! (which
still works), and Ruby's garbage collection would work fine and no
memory would be leaked.
Thoughts?
Cheers.
[1] id:20210427085343.2300-1-felipe.contreras@gmail.com
--
Felipe Contreras
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: The future of Ruby bindings
2021-04-30 22:14 The future of Ruby bindings Felipe Contreras
@ 2021-05-08 6:28 ` Felipe Contreras
0 siblings, 0 replies; 2+ messages in thread
From: Felipe Contreras @ 2021-05-08 6:28 UTC (permalink / raw)
To: notmuch@notmuchmail.org; +Cc: Ali Polatel
On Fri, Apr 30, 2021 at 5:14 PM Felipe Contreras
<felipe.contreras@gmail.com> wrote:
> I understand why Ali Polatel did commit c7893408 (ruby: Kill garbage
> collection related cruft., 2010-05-26); because the order of the object
> destruction cannot be ensured in Ruby, however, there's ways to
> workaround that.
>
> 1. We can steal the object
> 2. We can increase the reference count
> 3. We can add a second parent
I attempted all options, and none of these worked in practice, except #1.
I have the patches ready, but first they need the cleanups in [1].
Any feedback would be appreciated.
Cheers.
[1] id:20210504081749.715768-1-felipe.contreras@gmail.com
--
Felipe Contreras
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-05-08 6:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-30 22:14 The future of Ruby bindings Felipe Contreras
2021-05-08 6:28 ` Felipe Contreras
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
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).