From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id kI2SLEyBjGDoOAEAgWs5BA (envelope-from ) for ; Sat, 01 May 2021 00:14:36 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id tngyKEyBjGAODQAAB5/wlQ (envelope-from ) for ; Fri, 30 Apr 2021 22:14:36 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D1F7710C50 for ; Sat, 1 May 2021 00:14:35 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id F121E2717A; Fri, 30 Apr 2021 18:14:28 -0400 (EDT) Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by mail.notmuchmail.org (Postfix) with ESMTPS id 0E0BD1FBC5 for ; Fri, 30 Apr 2021 18:14:24 -0400 (EDT) Received: by mail-oi1-x231.google.com with SMTP id i81so71491559oif.6 for ; Fri, 30 Apr 2021 15:14:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:message-id:subject:mime-version :content-transfer-encoding; bh=8DmM7Wgn4POkJK9syBSr1GaP+cgQX2rXOpeDKw8Sok8=; b=HPDy7hwvV2dRmVrLIH8pyLG5++wWEymi8/bfFV02w3gucxlXCu8C/Pmgginr7zLIHC d3/lbbBwLHSxUaR+XeSnQa7oFPx0XZqlIOx5KYaNTCaO1jLEnwryeUoy/6KtglZzSjBF U7dQdkiuJtsVhT1AwKxopxhsK7Dpop3X6xSENCEOZPGy5faUnaQn4mKdt7f4oGCGhz3G C70OmmG6Xt3TaW7m4RUnytwqSCoujBrn5L0fA3xplshtJiXMHbU7fM3U+1YfLvbdlBvs IYXDX7WLlWfIbWMDYJZ4W8U3aqd68VoBClWsNyrXOrEKTm4uFAqkBByDjaHfgPRvx6ON mjnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:message-id:subject:mime-version :content-transfer-encoding; bh=8DmM7Wgn4POkJK9syBSr1GaP+cgQX2rXOpeDKw8Sok8=; b=HYun0oFchnFnDLbZN9iuHSSi1Qh4akCtoydzRA0ipO4QDB6xNMB64QlijTT1uEEmTY lARhjenUQl6cQUd0YPn2D7ptLH0e6Ja7LoF6bBo3e+GvNoAeOCQYNTTboja3co2oGCe+ YZqlJ5q5AUsQ+N5nW8a7yGymHlrb+BNRQqCZaHD1Y4RE44Gw1yWvOGd/lbXdnKwFfjZQ Ck2ft3t9uf1fn3mL0khnRLKYLQqpG82KXakBnGN43/LZClhzWZYSwzyA+Khig2xc1izO WLfM9ZRY4O8KjUuxoxkj7jGiQpSU1mm8M7TbrJlJXhVngDvKCRO7bHHioNKSsVcG/k3i zMyA== X-Gm-Message-State: AOAM532coGGrKFNpbYwf7T2rtnmnnaybgEmrez28+1u85QNurnm4N8Rt 0IJMrZ9yKzlNScMriWwk6YVGpNGBY11WiQ== X-Google-Smtp-Source: ABdhPJxuEkadMlm6Vvdi8kS28UDU3RXiPK2V4C03wEWvkp4qE0WPC6ZsMVBIhLpOFNcoY5gd7DT1dQ== X-Received: by 2002:aca:ea06:: with SMTP id i6mr5701729oih.82.1619820860361; Fri, 30 Apr 2021 15:14:20 -0700 (PDT) Received: from localhost (fixed-187-190-78-172.totalplay.net. [187.190.78.172]) by smtp.gmail.com with ESMTPSA id z9sm994096otj.44.2021.04.30.15.14.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 15:14:19 -0700 (PDT) Date: Fri, 30 Apr 2021 17:14:15 -0500 From: Felipe Contreras To: notmuch@notmuchmail.org Message-ID: <608c81378d0d0_fea2086d@natae.notmuch> Subject: The future of Ruby bindings Mime-Version: 1.0 Message-ID-Hash: RHSDIHSDTUWDL3QEXJFOIMF4CFXMUFUR X-Message-ID-Hash: RHSDIHSDTUWDL3QEXJFOIMF4CFXMUFUR X-MailFrom: felipe.contreras@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Ali Polatel X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1619820876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=eI4a375FH8+EkPA6jWnkgau53THs9rPH4OaaJ2Y7Mg8=; b=rzqTo4XItLhNxpgxY04bJ2zuolFGJ1ju1+AumGE31ocPFaEXvIw5zh/bWPWEBLDy7NwgQK rTmtjkl0EAPV2YrotSNuFfl+8u2MZo+dw+AAq14TzIQr3cF13jq1ctr/SM5V/9LuQ6z7DM CPF5tJnnVNxLem2t/nlx/GNI1IiVmqbBproB0RksnGGrBHrezFhBT7uHFXj/++gEyo4MWO U7kihom4otxU+cqs4aHf2BmQ96c4gmqEZzt/xs+xTYUmgCPVHPRom3a6PELSnyXQbWPkTv gVhEIqmVZ0HjNLmejRLJY0v1jS17IVg+SQ519+q3qQvcW3ck5shikfLh7ubErw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1619820876; a=rsa-sha256; cv=none; b=TP0qXkkuIZ+mUn7pBnZhIsGFbM6C99+3gdMHEI1X8MzMUHsrhtwaaEFkHkAx0Cy7Pg2sw0 mNrv+P13XAT+g5N0Qn1qDU4rlGfJnjbqVpVGyYe/rzPEXl4aFKOumjmsTv//IPPExsiV0m aWp4VsLCvPwjui7EyjO5oskBNHSCLvVCCRGI11BMFJLtJZt4HcN6AqJtC34+ARapIASiaH TtW7vQ5w5U4qIVqZXJb5AFGDb7mF3gsTUZKTzZkpS48+RUFZgTlKKiKCCvHdW0aLfxGDTD FsM3WljZenQV25SL+jOOU59R03eoa3kYvIl5Yk6oX9yNGlfVRzwWs+Dv3fukQw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=HPDy7hwv; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 1.09 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=HPDy7hwv; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: D1F7710C50 X-Spam-Score: 1.09 X-Migadu-Scanner: scn0.migadu.com X-TUID: 6d+noQGwZ1Wg 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