From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 3CBF53894C36 for ; Thu, 17 Nov 2022 09:47:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3CBF53894C36 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668678444; 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: in-reply-to:in-reply-to:references:references; bh=3i0iFmnET2pcbZdl/8CA6VywNwA6xYg1mSYgTSPRy34=; b=WjTre1Xeen9blw6te+7kHghVQRxJ3xCAiIjg1/6RnxAE+l/kZu+5Pb+rl/qAVAs41LL0VD 42pkOzwJlpl8S5OQryJDcZUbUl58K9q2BTzCypkJeDj2lKIjqJUH6uBOwSFaLDs2LL2jKG W06pu/HvFZRd4mNZLOEsEdYFlELAKz8= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-597-O64g8b0iN9a7NehgtERFGQ-1; Thu, 17 Nov 2022 04:47:22 -0500 X-MC-Unique: O64g8b0iN9a7NehgtERFGQ-1 Received: by mail-ed1-f72.google.com with SMTP id h9-20020a05640250c900b00461d8ee12e2so863281edb.23 for ; Thu, 17 Nov 2022 01:47:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=3i0iFmnET2pcbZdl/8CA6VywNwA6xYg1mSYgTSPRy34=; b=a0PM65nnnIetpsd6cCwmRnIGpvldu3Y9apABbIoJsJFds3+eQdVZkDfsFIQbZNJUGA 9qaB7QdNYTVBKH6reyre2TTaRS9r9DtjNWqWbJ7r00mm7EooSTMJvis50Wu7E6CjPlsV EH3ZCr35zTB+x/3EIhNmKGNQOnW+mzwClyzGmm25gZQ6s2nQWXO4aVNDTP/kv4ZYo+JZ 8RgbYL8h4TLLjUngSaSpwFmcKMRip8wSkd40LeYtvXCxgNToOHxOCr0uAiGIQjrmvMpa c1AXXnWWbs3fcGojct1zhos7Xnyln+zSLACay9RaogPo/OFnFVSsJaXHaFo+YqAjSrIr qebw== X-Gm-Message-State: ANoB5pnpqK/s2kToiBzQRHU9H1tNT2/IQERHvkGRkYxfsBEnslapJXiD UvyQLvwBoZvOSsWtMaItOFuIM+ISdBdEhqs9mlCFvUVRzTBdTIfiSeeSam3YwY2L7hPghDaAlJ0 XCaO8kW2RUWkTi8vl3xRi6mIKA2/uFmo= X-Received: by 2002:aa7:d5c9:0:b0:463:c64e:bc75 with SMTP id d9-20020aa7d5c9000000b00463c64ebc75mr1463508eds.205.1668678441806; Thu, 17 Nov 2022 01:47:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf6WHlCgEHhrhBKfsuNdN9dliXR721lLkA2nPbpo/P6TXTwd4HNnD1/YC/fN0QkxCFkJ4W33wkECMPfl+ym0KlU= X-Received: by 2002:aa7:d5c9:0:b0:463:c64e:bc75 with SMTP id d9-20020aa7d5c9000000b00463c64ebc75mr1463502eds.205.1668678441637; Thu, 17 Nov 2022 01:47:21 -0800 (PST) MIME-Version: 1.0 References: <20221116210014.1420128-1-jwakely@redhat.com> In-Reply-To: From: Jonathan Wakely Date: Thu, 17 Nov 2022 09:47:10 +0000 Message-ID: Subject: Re: [committed] libstdc++: Improve performance of chrono::utc_clock::now() To: =?UTF-8?Q?Daniel_Kr=C3=BCgler?= Cc: Jonathan Wakely , "libstdc++" , gcc-patches X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="000000000000c226c205eda77981" X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000c226c205eda77981 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, 17 Nov 2022 at 09:25, Daniel Kr=C3=BCgler wrote: > Am Do., 17. Nov. 2022 um 10:07 Uhr schrieb Jonathan Wakely > : > > > > > > > > On Thu, 17 Nov 2022, 06:30 Daniel Kr=C3=BCgler via Libstdc++, < > libstdc++@gcc.gnu.org> wrote: > >> > >> Am Mi., 16. Nov. 2022 um 22:00 Uhr schrieb Jonathan Wakely via > >> Libstdc++ : > >> > > >> > Tested x86_64-linux. Pushed to trunk. > >> > > >> > -- >8 -- > >> > > >> > We can use an array instead of a std::vector, and we can avoid the > >> > binary search for the common case of a time point after the most > recent > >> > leap second. On one system where I tested this, utc_clock::now() now > >> > takes about 16ns instead of 31ns. > >> > > >> > libstdc++-v3/ChangeLog: > >> > > >> > * include/std/chrono (get_leap_second_info): Optimize. > >> > --- > >> > libstdc++-v3/include/std/chrono | 31 ++++++++++++++++++++++++------- > >> > 1 file changed, 24 insertions(+), 7 deletions(-) > >> > > >> > diff --git a/libstdc++-v3/include/std/chrono > b/libstdc++-v3/include/std/chrono > >> > index 90b73f8198e..2468023f6c5 100644 > >> > --- a/libstdc++-v3/include/std/chrono > >> > +++ b/libstdc++-v3/include/std/chrono > >> > @@ -2747,9 +2747,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > >> > { > >> > if constexpr (is_same_v<_Duration, seconds>) > >> > { > >> > - // TODO move this function into the library and get leaps > from tzdb. > >> > - vector __leaps > >> > - { > >> > + const seconds::rep __leaps[] { > >> > 78796800, // 1 Jul 1972 > >> > 94694400, // 1 Jan 1973 > >> > 126230400, // 1 Jan 1974 > >> > @@ -2778,12 +2776,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > >> > 1435708800, // 1 Jul 2015 > >> > 1483228800, // 1 Jan 2017 > >> > }; > >> > + // The list above is known to be valid until 2023-06-28 > 00:00:00 UTC > >> > + const seconds::rep __expires =3D 1687910400; > >> > + const seconds::rep __s =3D __ut.time_since_epoch().count= (); > >> > > >> > - auto __s =3D __ut.time_since_epoch().count(); > >> > - auto __pos =3D std::upper_bound(__leaps.begin(), > __leaps.end(), __s); > >> > + const seconds::rep* __first =3D std::begin(__leaps); > >> > + const seconds::rep* __last =3D std::end(__leaps); > >> > + > >> > + if (__s > __expires) > >> > + { > >> > + // TODO: use updated leap_seconds from tzdb > >> > +#if 0 > >> > + auto __db =3D get_tzdb_list().begin(); > >> > + __first =3D __db->leap_seconds.data(); > >> > + __last =3D __first + __db->leap_seconds.size(); > >> > +#endif > >> > + } > >> > + > >> > + // Don't bother searching the list if we're after the > last one. > >> > + if (__s > __last[-1]) > >> > + return { false, seconds(__last - __first) }; > >> > + > >> > + auto __pos =3D std::upper_bound(__first, __last, __s); > >> > return { > >> > - __pos !=3D __leaps.begin() && __pos[-1] =3D=3D __s, > >> > - seconds{__pos - __leaps.begin()} > >> > + __pos !=3D begin(__leaps) && __pos[-1] =3D=3D __s, > >> > >> The inconsistency between usage of std::begin versus begin here seems > >> odd and I'm wondering why instead of "begin(__leaps)" the above > >> introduced "__first" variable is not used instead. > > > > > > Because this code is going to be changed again soon, this is a partial > merge from a local branch with the TODO fixed. Yes, it's inconsistent, but > it works correctly and it's not my priority right now :-) > > What about the suggestion to use the already existing "__first" > variable instead of the begin call? > It's an array, the begin call is free. --000000000000c226c205eda77981--