From nobody Fri Sep 13 07:59:08 2024 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4X4mt13QVcz5WJDv for ; Fri, 13 Sep 2024 07:59:21 +0000 (UTC) (envelope-from joesuf4@gmail.com) Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X4mt108jFz4Xgy; Fri, 13 Sep 2024 07:59:21 +0000 (UTC) (envelope-from joesuf4@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-374cacf18b1so1251070f8f.2; Fri, 13 Sep 2024 00:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726214359; x=1726819159; darn=freebsd.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=yd01X5TCKIUt/P/vypMqhZBf19sYgiopPKG2R43NoCY=; b=SCjuh29q1doz3aByCIKjfXzrSqf2IsnSr3O3DGA097Hf2BpIgix6xheVJsyyKAI1pv kaCNEhC521/0T2iUSEg/V+Hq90GFPpo838s0lGhWJQOONacgErqZUPMWOBPf3ktgh8Fa FGluG/Hf42pm4dlUIBI94AF4blW2apzNHVfldubZrJW1RfrnsnS04hEcYYJI1kPR30E2 92X0nolZMpWLxDXJUMrtegnsHzBdZFZe5oMs0IR79X2iIAL7CU0PGwTCYXbNhOOAjOq8 zP2Sds0k+bM3e3skt+jsvccBWmhuyDCaHCPUeCIKUkXVaUCsQGwuJrqnjUdxoAAHxTgt /iVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726214359; x=1726819159; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yd01X5TCKIUt/P/vypMqhZBf19sYgiopPKG2R43NoCY=; b=CvpHdZ5o1p4c1liMwGvHIPyNFoDXfJSKJxQ8pHDJ73h+CiLYzJuLoIyWg3ZBCYs+1n vBvvaie150YnrKcB+Us+bHPKnre5gXrQMGt0pZo/QJehyGORaZeuFdC9zJyv1xTPoOVZ wqZLxxFcfUzaEIADcPpqWBx2L9m+dyky5Z+8Iru4tPQZIPk/w+T6JGj9G6N7TnXN/DPv 4av1VQlfC/ltjwu5SZXQgWv9qVNf5cq5+W4+zkskS4QQrUhd6xMeCq1WiagavN6/xqpY /MAhWHZDRuPxrozGThdZ1wqV0xaSzgcso5AulLiuehzI6MNfGd8gzypGcCE+W4ucnMCg VwIA== X-Forwarded-Encrypted: i=1; AJvYcCUCdkDBJ5HHtq22USqC3ERt5JBbvtSww0NyWqxQoacgAbJl4nqdswjFzZXgIg7GC9PFQbT3s+m1@freebsd.org, AJvYcCWyALV/CPbTifEDoTLU6fy7L5gynzCzELzsV/cVOA8n7+jAau0SfCwp6p1UFyw05mr0N2P2Lecd5wQnz1rkCXnZ@freebsd.org X-Gm-Message-State: AOJu0YxXFDR0W0tTXU4qDuTIPbRzs9fCo0AjdCAH28ZN41j2s1txOJin mD7LmiOt5+Jkr1yQMSL+2YwyVN9DAG4kYHRIAMiYh60Fb+CsaVLlBDaDZYQZqBulTd8s16Uj78/ tlRaKBAlsH0CQAfsYXt6bWF9u3cWBDHGK X-Google-Smtp-Source: AGHT+IFGPQ9MbZPy3UWV1M1Ihegvi7xcFebycfh70TL0HA6fdeobrQ9BsFLDzEbKrNItNyCO+J/ehIz4PTvPJc3dTpM= X-Received: by 2002:a5d:42c7:0:b0:374:bfb2:39d with SMTP id ffacd0b85a97d-378c2d4d6d5mr3140438f8f.38.1726214359051; Fri, 13 Sep 2024 00:59:19 -0700 (PDT) List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@FreeBSD.org MIME-Version: 1.0 References: <2EE309BF-CE1D-48AD-9C53-D4C87998B4A0@freebsd.org> In-Reply-To: <2EE309BF-CE1D-48AD-9C53-D4C87998B4A0@freebsd.org> From: Joe Schaefer Date: Fri, 13 Sep 2024 03:59:08 -0400 Message-ID: Subject: Re: The Case for Rust (in any system) To: David Chisnall Cc: Pat Maddox , Alan Somers , Chris , Warner Losh , FreeBSD Hackers Content-Type: multipart/alternative; boundary="000000000000ad77ca0621fb990c" X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US] X-Rspamd-Queue-Id: 4X4mt108jFz4Xgy --000000000000ad77ca0621fb990c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable That=E2=80=98s because you are a dork. The point isn=E2=80=99t that callo= c calls are faster than vector allocations. The point is that by changing the way you deal with arrays (as objects that manage their own size, versus managing the sizes using up front preallocations and dealing with their growth yourself), we can exchange function calls for pointer dereferences. An order of magnitude improvement just by reorganizing the way array element access is performed. On Fri, Sep 13, 2024 at 2:17=E2=80=AFAM David Chisnall wrote: > On 13 Sep 2024, at 02:34, Joe Schaefer wrote: > > > > I just completed a month long project to port a C++ codebase that used > vectors for array allocations back to using C=E2=80=98s calloc. For a 15%= increase > in memory footprint, batch jobs that took three days to complete now fini= sh > in 10-12 hours. > > This sounds highly dubious given that std::vector is a very thin wrapper > around malloc. From your description, I would expect the same speedup wit= h > some judicial use of .reserve(). > > David --000000000000ad77ca0621fb990c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
That=E2=80=98s =C2=A0because you are a dor= k.=C2=A0 The point isn=E2=80=99t that calloc calls are faster than vector a= llocations. =C2=A0 The point is that by changing the way you deal with arra= ys (as objects that manage their own size, versus managing the sizes using = up front preallocations and dealing with their growth yourself), we can exc= hange function calls for pointer dereferences.
=
An order of magnitude improvement just by = reorganizing the way array element access is performed.


On Fri, Sep 13, 2024 at 2:17=E2=80=AFAM David Chisnall <theraven@freebsd.org> wrote:
On 13 Sep 2024, at 02:34, Joe Schaefer <joesuf4@gmail.com> wrote:
>
> I just completed a month long project to port a C++ codebase that used= vectors for array allocations back to using C=E2=80=98s calloc. For a 15% = increase in memory footprint, batch jobs that took three days to complete n= ow finish in 10-12 hours.

This sounds highly dubious given that std::vector is a very thin wrapper ar= ound malloc. From your description, I would expect the same speedup with so= me judicial use of .reserve().

David
--000000000000ad77ca0621fb990c--