From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: Optimizing =?utf-8?b?4oCYc3RyaW5nPeKAmQ==?= Date: Tue, 22 Jun 2010 23:32:43 +0200 Message-ID: <87eifyhhxg.fsf@gnu.org> References: <87k4pqj1pc.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1277242907 25943 80.91.229.12 (22 Jun 2010 21:41:47 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 22 Jun 2010 21:41:47 +0000 (UTC) Cc: guile-devel@gnu.org To: Andy Wingo Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Jun 22 23:41:45 2010 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ORBDw-0006gb-0D for guile-devel@m.gmane.org; Tue, 22 Jun 2010 23:41:40 +0200 Original-Received: from localhost ([127.0.0.1]:47970 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ORB7U-0006N5-AC for guile-devel@m.gmane.org; Tue, 22 Jun 2010 17:35:00 -0400 Original-Received: from [140.186.70.92] (port=44156 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ORB7G-0005fx-Qo for guile-devel@gnu.org; Tue, 22 Jun 2010 17:34:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1ORB5M-0000LY-Da for guile-devel@gnu.org; Tue, 22 Jun 2010 17:32:49 -0400 Original-Received: from mail4-relais-sop.national.inria.fr ([192.134.164.105]:17485) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1ORB5M-0000LQ-8v for guile-devel@gnu.org; Tue, 22 Jun 2010 17:32:48 -0400 X-IronPort-AV: E=Sophos;i="4.53,462,1272837600"; d="scan'208";a="65126439" Original-Received: from reverse-83.fdn.fr (HELO nixey) ([80.67.176.83]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 22 Jun 2010 23:32:46 +0200 X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 4 Messidor an 218 de la =?iso-8859-1?Q?R=E9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu In-Reply-To: (Andy Wingo's message of "Tue, 22 Jun 2010 22:51:13 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:10551 Archived-At: Hi, Andy Wingo writes: > On Tue 22 Jun 2010 21:40, ludo@gnu.org (Ludovic Court=C3=A8s) writes: > >> @@ -1168,6 +1168,21 @@ SCM_DEFINE (scm_string_eq, "string=3D", 2, 4, 0, >> "value otherwise.") >> #define FUNC_NAME s_scm_string_eq >> { >> + if (SCM_LIKELY (scm_i_is_narrow_string (s1) =3D=3D scm_i_is_narrow_st= ring (s2) >> + && SCM_UNBNDP (start1) && SCM_UNBNDP (end1) >> + && SCM_UNBNDP (start2) && SCM_UNBNDP (end2))) >> + { >> + size_t len1, len2; >> + >> + len1 =3D scm_i_string_length (s1); >> + len2 =3D scm_i_string_length (s2); >> + >> + if (SCM_LIKELY (len1 =3D=3D len2)) >> + return scm_from_bool (memcmp (scm_i_string_chars (s1), >> + scm_i_string_chars (s2), >> + len1) =3D=3D 0); >> + } >> + > > Nasty, but OK I guess if you need it. Why not also add a fast path for > scm_is_eq (s1, s2), or for comparing stringbufs, or something ? Hmm yes. Though if there are too many fast paths the whole thing ends up being slow. ;-) I don=E2=80=99t expect (eq? s1 s2) and (eq? (string-buf s1) (string-buf s2)= ) to be common enough to warrant a more specific special case, though. >> It=E2=80=99s quite inelegant, but it leads to a more balanced profile: >> >> samples % symbol name >> 8079 23.3984 scm_string_eq >> 5649 16.3606 vm_debug_engine >> 5624 16.2882 scm_i_str2symbol > ^ What is this doing here? I comes from the =E2=80=98load-symbol=E2=80=99 instruction. Indeed, the loop=E2=80=99s body goes like this: --8<---------------cut here---------------start------------->8--- 36 (new-frame)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20 37 (load-symbol "string=3D") ;; string=3D 48 (link-now)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20 49 (variable-ref)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 50 (load-symbol "s") ;; s 55 (link-now)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20 56 (variable-ref)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 57 (load-symbol "s") ;; s 62 (link-now)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20 63 (variable-ref)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 64 (mv-call 2 :L39) ;; MV -> 74 69 (drop)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20 70 (br :L40) ;; -> 77 74 (truncate-values 0 0)=20=20=20=20=20=20=20=20=20=20=20 77 (br :L41) ;; -> 36 81 (br :L41) ;; -> 36 --8<---------------cut here---------------end--------------->8--- Because it=E2=80=99s a top-level program, =E2=80=9Cstring=3D=E2=80=9D is lo= oked up at each iteration. If we instead do: --8<---------------cut here---------------start------------->8--- (define s (make-string 123 #\a)) (define (foo) (let loop () (string=3D s s) (loop))) (foo) --8<---------------cut here---------------end--------------->8--- we get: --8<---------------cut here---------------start------------->8--- 0 (assert-nargs-ee/locals 0)=20=20=20=20=20=20 2 (br :L38) ;; -> 30 6 (new-frame)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20 7 (toplevel-ref 1)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 9 (toplevel-ref 2)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 11 (toplevel-ref 2)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 13 (mv-call 2 :L39) ;; MV -> 23 18 (drop)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20 19 (br :L40) ;; -> 26 23 (truncate-values 0 0)=20=20=20=20=20=20=20=20=20=20=20 26 (br :L41) ;; -> 6 30 (br :L41) ;; -> 6 --8<---------------cut here---------------end--------------->8--- and thus presumably no =E2=80=98scm_i_str2symbol=E2=80=99. > And for the matter, what are the rest about? Lookups of =E2=80=98string=3D=E2=80=99. > Did you just do a really short profile? Yes. Ludo=E2=80=99.