From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.bugs Subject: bug#65491: [PATCH] Improve performance allocating vectors Date: Mon, 28 Aug 2023 10:14:49 +0000 Message-ID: <87il8z323q.fsf@localhost> References: <87y1i0iwvu.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34917"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 65491@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Aug 28 12:15:22 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qaZHF-0008rq-Hk for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 28 Aug 2023 12:15:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qaZGt-0004js-Jc; Mon, 28 Aug 2023 06:14:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qaZGq-0004jf-Rr for bug-gnu-emacs@gnu.org; Mon, 28 Aug 2023 06:14:57 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qaZGq-0007Gx-5V for bug-gnu-emacs@gnu.org; Mon, 28 Aug 2023 06:14:56 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qaZGw-0005a0-EJ for bug-gnu-emacs@gnu.org; Mon, 28 Aug 2023 06:15:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ihor Radchenko Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 28 Aug 2023 10:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65491 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 65491-submit@debbugs.gnu.org id=B65491.169321767521397 (code B ref 65491); Mon, 28 Aug 2023 10:15:02 +0000 Original-Received: (at 65491) by debbugs.gnu.org; 28 Aug 2023 10:14:35 +0000 Original-Received: from localhost ([127.0.0.1]:47035 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qaZGV-0005Z2-Cb for submit@debbugs.gnu.org; Mon, 28 Aug 2023 06:14:35 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:49485) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qaZGS-0005Ym-K0 for 65491@debbugs.gnu.org; Mon, 28 Aug 2023 06:14:34 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 0CF30240027 for <65491@debbugs.gnu.org>; Mon, 28 Aug 2023 12:14:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1693217660; bh=dxRiCP9mDMWCb/5rmWmsSMFxzFgsKBHUOTzH0tH7AEQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=Q3t1HR0ugVBVl+V3FOFMyFU51jK+CPs5kl+7xQ4EGDAbxcqJZ3jaK5oHcfhvn0NgA IjyQ6+nDGod5jeKujvjgCTbZJzmnmL3bx4YhsBW+2Vg3NWFfYfZCicq+7s6dyjSwtk aMzxJ23Vj6XCNbad0B93bVy5sBmZxDsx9QUiBFCsJiBHO888OYA8NH/M4shW+UWflU SeA+Wu4BMFW7Yc/k3MV/jLf/18r6t/fK3v8HRCFOV6gi9ajAiK400TYTjk1mwfhE9k 8xrcZbiO2FLp6mB6naak2TlyyC+wukXkcpXkQ30GPlXMetGV5TPo5U6YoN8WtdGZOT zfu5CLtK1pVdw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RZ5y32PbBz9rxD; Mon, 28 Aug 2023 12:14:18 +0200 (CEST) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:268612 Archived-At: Stefan Monnier writes: >> +static ptrdiff_t last_known_vector_free_idx = VECTOR_MAX_FREE_LIST_INDEX; >> /* Singly-linked list of large vectors. */ >> >> static struct large_vector *large_vectors; > > There's clearly some spacing issue with the following comment but more > importantly the new var would need a good comment explaining what the > variable should hold and why it's useful, so we know when it's safe and > desirable to set or use the var. Sure. I can add a comment. However, from previous answers, we may better rewrite the vector allocation code more significantly. >> - for (index = VINDEX (nbytes + VBLOCK_BYTES_MIN); >> + for (index = max (VINDEX (nbytes + VBLOCK_BYTES_MIN), last_known_vector_free_idx); >> index < VECTOR_MAX_FREE_LIST_INDEX; index++) >> if (vector_free_lists[index]) >> { > > IIUC that's the core of your patch. Nice. >> memset (vector_free_lists, 0, sizeof (vector_free_lists)); >> + last_known_vector_free_idx = VECTOR_MAX_FREE_LIST_INDEX; >> >> /* Looking through vector blocks. */ > > Hmm... so I was wrong and after GC there are aren't any free vectors? > I need to go re-read that code, then, because it doesn't match my mental > model of how it work(s|ed). Interestingly, when I just tried to skip searching vector_free_lists when there are no vectors available there, it yielded to no significant improvement. Only that max(VINDEX (...), last_known_vector_free_idx) yielded a good performance improvement. The reason might be that vector sizes are distributed non-uniformly and some segments of vector_free_lists are filled more than others. It could be a good exercise to look into statistics of how vector_free_lists is filled. Is there some standard way to print debug information from the allocation code? -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at