From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Gerd_M=C3=B6llmann?= Newsgroups: gmane.emacs.devel Subject: Re: MPS: dangling markers Date: Sat, 29 Jun 2024 20:12:39 +0200 Message-ID: References: <87v81u85hv.fsf@localhost> <87frsx81m2.fsf@localhost> <87cyo180y2.fsf@localhost> <874j9d7zqe.fsf@localhost> <87sewvg6lw.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="38477"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Ihor Radchenko , emacs-devel@gnu.org, Eli Zaretskii , eller.helmut@gmail.com To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jun 29 20:13:04 2024 Return-path: Envelope-to: ged-emacs-devel@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 1sNcZM-0009oC-Ad for ged-emacs-devel@m.gmane-mx.org; Sat, 29 Jun 2024 20:13:04 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sNcZ5-0006TI-2z; Sat, 29 Jun 2024 14:12:47 -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 1sNcZ3-0006T3-Jb for emacs-devel@gnu.org; Sat, 29 Jun 2024 14:12:45 -0400 Original-Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sNcZ1-0005we-TV; Sat, 29 Jun 2024 14:12:45 -0400 Original-Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-52cdb0d8107so2009032e87.1; Sat, 29 Jun 2024 11:12:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719684761; x=1720289561; darn=gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=aZg8AxLFddRFutaUkrpH3R5m6C+PL44zsXLUEtrJ138=; b=GQYiB3pWLmW8yu7akiSf3jq5VRNOOLqyjT+K04Ry1bf8SnkyAnbErNfl/fV94wgZD0 O33dUR9dLLX9jyXEXZn/g3LBoqXEiUApKi867WyaB+gRrV1gFXjnVUuPmAPMnZPo41Wa IWjM84XkyRnvWZaEYUEI4IvJ1zqiQG2qphQXe3G5rx/jMAQz+qy4tgGvwG1+PJGWaFWr uUk4oQvRmkG3mE3O5dbtniBupML9t82mgA33kPMzeuKzFaWbX8afZ+Z19YMMheE3DWFv 8NggZRR0lZfAme5m2EMO6kdVWHkyw1OM2/ZIpQGJklzIFIpN3fEppbl1l8L4MYLoeEyu 9b8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719684761; x=1720289561; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=aZg8AxLFddRFutaUkrpH3R5m6C+PL44zsXLUEtrJ138=; b=EV7lcliaQ5ZgCjiFIkOam04x0D5woz926LmXgZHav347lXtZpYxriSHP6IC5w8wg0i Ej8PPNs8hINNiEXXpPOD6bV7WM2rL0uIMz4nGjKMx9+NeT111L3SZE3ovB47D5xVhlaE AG6oXuX+vSeYkO0TfxUEu1t1q9LTti5Lvy3rjmJk1Ra6jP40wnupofsOWb0FaYFbT1u0 At+rfDZyFbW+dZ/6uq6QarlUH7IcVPPBzSCLUH2Rt+o4AqH32/lk+5DOdaBtgrC8YXWa Sw4/zgtkCEu1nJ9ZDWkXNoQdiCDZ1Vhfriwl4OhtGv/pDr/Go3YpC9hMZkPYGiNIv1kI rW4g== X-Forwarded-Encrypted: i=1; AJvYcCWrFnW8qN6Gd4XAtjzUNIxzM+h9Q8hO1W4diTWJaMCIC66uS3UzNfCDtqCQ8l/G8CYbq+jpoVtvtdN7Cf05eJLXhy1k47DiiXFQTr/pEUuNijw= X-Gm-Message-State: AOJu0YyPF6SMqUgqnmdeGA/v/7CzVAxHmDmLl9WFDoseHmmfMoWktukG JMKZILOIQ0MxnVB9tOrC4rnqMYVNT/1/ECFgCBgZFTj4aTxvAiqV X-Google-Smtp-Source: AGHT+IG5agpw+HMRUiurWsksUpSyaHIoXBMaKSljSjXilK1A1BdwBLWbi89D4obN2tOKM+uYKyLM4g== X-Received: by 2002:a05:6512:acc:b0:52c:812b:6e72 with SMTP id 2adb3069b0e04-52e8264cbf4mr1044844e87.1.1719684760357; Sat, 29 Jun 2024 11:12:40 -0700 (PDT) Original-Received: from pro2.fritz.box (pd9e36598.dip0.t-ipconnect.de. [217.227.101.152]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72ab0901adsm179642966b.185.2024.06.29.11.12.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jun 2024 11:12:40 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Sat, 29 Jun 2024 13:16:27 -0400") Received-SPF: pass client-ip=2a00:1450:4864:20::12e; envelope-from=gerd.moellmann@gmail.com; helo=mail-lf1-x12e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:320878 Archived-At: Stefan Monnier writes: >>> 36.34% emacs emacs [.] igc_remove_marker >>> 35.77% emacs emacs [.] igc_add_marker > > I don't understand this: > > - Why is `igc_remove_marker` slower than `unchain_marker`? > `unchain_marker` is also O(N), but should have a worse constant > because of the linked-list structure suffering much more from > memory latency. > > - Why does `igc_add_marker` take as much time as `igc_remove_marker`? > `igc_add_marker` only needs to find an empty spot (whereas > `igc_remove_marker` needs to find the one and only spot that holds > the marker), so while it's also O(N) in the worst case, it should be > faster on average. Yes, that doesn't make much sense to me either. add_marker even includes allacaton/re-allocation costs. Can it be that remove_marker is called much more often than add_marker? @Ihor, do can see call counts? void igc_add_marker (struct buffer *b, struct Lisp_Marker *m) { Lisp_Object v = BUF_MARKERS (b); if (NILP (v)) v = BUF_MARKERS (b) = alloc_vector_weak (1, Qnil); ptrdiff_t i = find_nil_index (v); if (i == ASIZE (v)) v = BUF_MARKERS (b) = larger_vector_weak (v); Lisp_Object marker = make_lisp_ptr (m, Lisp_Vectorlike); ASET (v, i, marker); } void igc_remove_marker (struct buffer *b, struct Lisp_Marker *m) { m->buffer = NULL; Lisp_Object v = BUF_MARKERS (b); igc_assert (VECTORP (v)); Lisp_Object marker = make_lisp_ptr (m, Lisp_Vectorlike); for (ptrdiff_t i = 0; i < ASIZE (v); ++i) if (EQ (AREF (v, i), marker)) { ASET (v, i, Qnil); break; } } > [ FWIW, I'm incidentally playing with an implementation of the "set of > markers" as an ordered array-with-gap, so bytes<->chars conversions > take O(log N) time for N markers, because we can use binary search. > Removal and addition of a marker can also use the binary search to > find the spot, tho it's still O(N) overall because of the need to move > the gap, but hopefully the gap is usually nearby already (and the > constant is much smaller because it's just a `memmove`). > Mostly fighting with the pdumper now. ] Hey, that's really really good! :-)