From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id EC1597EE89 for ; Wed, 25 Oct 2017 11:31:37 +0200 (CEST) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=christoph.hoeger@celeraone.com; spf=Pass smtp.mailfrom=christoph.hoeger@celeraone.com; spf=None smtp.helo=postmaster@mail-vk0-f41.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of christoph.hoeger@celeraone.com) identity=pra; client-ip=209.85.213.41; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="christoph.hoeger@celeraone.com"; x-sender="christoph.hoeger@celeraone.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of christoph.hoeger@celeraone.com designates 209.85.213.41 as permitted sender) identity=mailfrom; client-ip=209.85.213.41; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="christoph.hoeger@celeraone.com"; x-sender="christoph.hoeger@celeraone.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-vk0-f41.google.com) identity=helo; client-ip=209.85.213.41; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="christoph.hoeger@celeraone.com"; x-sender="postmaster@mail-vk0-f41.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3A8AsB4BJXiqEqRr4z8dmcpTZWNBhigK39O0sv0rFi?= =?us-ascii?q?tYgUK//xwZ3uMQTl6Ol3ixeRBMOAtKIC1rKempujcFJDyK7JiGoFfp1IWk1Nou?= =?us-ascii?q?QttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBX660e/5j8KGxj5KRE9?= =?us-ascii?q?ZqGsQtaT3IyL0LWV0JTWZ01tjTu5YLV9ZDG3thmZ4sIfhI8nLqcq1jPIpGFJcq?= =?us-ascii?q?JY3zU7C0iUmkPX5t2x54Jk6yRnm2wu+tQIBa76ZaUjUbtADHImNG066dfDvhTH?= =?us-ascii?q?QBGG4X0RFG4Rl0wbUED+8BjmU8Kp4WPBve1n1XzfZJWuQA=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0CVAQCYWfBZhynVVdFaHRgHDAEFAQsBh?= =?us-ascii?q?QYnB4NzgTaYHZJyhVKBIgNcCoofB0MUAQEBAQEBAQEBAQESAQEBCA0JCCgvgjg?= =?us-ascii?q?FAR4BBYJlHQEBOBgGBzcCJBIBBQEiG4oYi1ORG0CLIWuCJ4MIAQEFiCwIEoMcg?= =?us-ascii?q?geLMINMgmGheJR3kyaVbRQFH4EVNoF8eoETBoIpgmyBdT42AYpGgVUBAQE?= X-IPAS-Result: =?us-ascii?q?A0CVAQCYWfBZhynVVdFaHRgHDAEFAQsBhQYnB4NzgTaYHZJ?= =?us-ascii?q?yhVKBIgNcCoofB0MUAQEBAQEBAQEBAQESAQEBCA0JCCgvgjgFAR4BBYJlHQEBO?= =?us-ascii?q?BgGBzcCJBIBBQEiG4oYi1ORG0CLIWuCJ4MIAQEFiCwIEoMcggeLMINMgmGheJR?= =?us-ascii?q?3kyaVbRQFH4EVNoF8eoETBoIpgmyBdT42AYpGgVUBAQE?= X-IronPort-AV: E=Sophos;i="5.43,431,1503352800"; d="scan'208,217";a="242293522" Received: from mail-vk0-f41.google.com ([209.85.213.41]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 25 Oct 2017 11:31:14 +0200 Received: by mail-vk0-f41.google.com with SMTP id g11so11955379vkd.13 for ; Wed, 25 Oct 2017 02:31:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=celeraone-com.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=FPMcbXiHZiUKtQnuCt4ueSbN+UpqcM0TjDuVHpCu6vE=; b=rFkmkCYlyTZ5WGvwyXuivPAM788RL2Ky5fynvFTWafW7WxgFOB0FNYKsM4xhO3h2Hi QidaO1A2q7gWmEcfG0mmA8WbJnt7K1cjR9DlSyZq/47bWWxjw1X9idPBKf8e/zjE2Wsg Zp+EsxCV/SRyTTfE0191F8xxOSx7zdtFDqFg/SW9fuielir9ELbIpsEs5g2b+3s+LsPt QN7snmMx0tWTkUVTyb8eLE9UMp8dv+c6tqY410Hm2OFBrSjHacfucvmtJh8uKNmZCFvK eoovkRt7EM1i7P61B/bZYK1z1vyZuWuuKh8LTM1NdKnMQOnz49QeTwH7u2ewEeBG1pJQ XjXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=FPMcbXiHZiUKtQnuCt4ueSbN+UpqcM0TjDuVHpCu6vE=; b=KQso2JlxbP1WbuqS5f55Qne27XoSa9EznEREjnGs4jdu6zxNFZsoiNT4ShnQtOiUK8 HAFiLf3JCJ8M3kezQpkXbw3PdPl/WholsR0KE+xvaOv+IA7wFt6TmAmFdYmJCrK0v4LN CnKlcfaK9vjCp9VgPXeONvUzFmmp3YMvEjkFTtiBWHowcZbqkIZjbE7bJKN6s7GzJvgR rqcSLK0EHCPFlnxYEx8w/pWPqGYY6SaKJ0/PWZKwSV73CiAHsDl8paB3XvuidbqL0mDL XI+RjavWS+e9njIHKojzwSe+9V3K5+dX//u3VhmGhkItsF+LRxWqounnpNPbQamIk7bT 7LBw== X-Gm-Message-State: AMCzsaWQ6V0gdWfIyV7TxwGdMWNUru45NaSHwqOLxozz4LwcpbVeV7bB mtfOBfxA5ortKpLfnusyKSH1neng16KW2wY09AaMHzIG X-Google-Smtp-Source: ABhQp+RXP7QklVJON/D8DQY+90g6U8cpCAiwQ+QD1b6jKwiImP/0SKrSX/YPzYAAOqx1VVTZVdESLLc2wwjeKUnDkA8= X-Received: by 10.31.248.203 with SMTP id w194mr1012179vkh.85.1508923872814; Wed, 25 Oct 2017 02:31:12 -0700 (PDT) MIME-Version: 1.0 Received: by 10.176.24.209 with HTTP; Wed, 25 Oct 2017 02:31:12 -0700 (PDT) From: =?UTF-8?Q?Christoph_H=C3=B6ger?= Date: Wed, 25 Oct 2017 11:31:12 +0200 Message-ID: To: OCaml Mailing List Content-Type: multipart/alternative; boundary="94eb2c14c6846ebe76055c5bb745" Subject: [Caml-list] classes not optimized? --94eb2c14c6846ebe76055c5bb745 Content-Type: text/plain; charset="UTF-8" Dear OCaml users, consider the following microbenchmark: class s (z : string) (y : int) (x : int) = object method z = z method y = y method x = x end type t = { x : int; y : int; z : string} let foo_s _ = (new s) "Example" 0 1 let foo_t _ = {x=1; y=0; z="Example"} let one_s _ = (foo_s ())#x let one_t _ = (foo_t ()).x let fac = let rec fac n = let f = let rec f n a = if n <= 1 then a else f (n - (one_s ())) (n * a) in f (* change one_t to one_s or vice-versa *) in f n 1 in fac let bench = let rec bench n a = if n <= 0 then a else (let x = a && ((fac 20) == (20 * (fac 19))) in bench (n - 1) x) in bench let test = bench 10000000 true let main _ = test If I run it with ocamlopt 4.05.0+flambda and -O3, the version that uses one_s takes about 7.5s whereas the one with one_t uses 0.35s. I know that object method lookup is more costly than records, of course. This particular case baffles me, though. Why is the class not completely inlined? Also as a related question, is there a way to have the lookup semantics of methods without the open recursion part? That is, can I have a class that consists of values, not methods? It would love to have open tuples in some cases. For example, I'd like to write a function that takes a tuple of any length, because it only needs the first element. thanks, Christoph --94eb2c14c6846ebe76055c5bb745 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Dear OCaml users,

co= nsider the following microbenchmark:

<snip&= gt;
class s (z : string)=C2=A0 (y : int)=C2=A0 (x : int) =3D<= br>=C2=A0 object method z =3D z method y =3D y method x =3D x
end
type t =3D { x : int; y : int; z : string}

let foo_s _ =3D
=C2= =A0(new s) "Example" 0 1

let foo_t _ =3D {x=3D1; y=3D0; z= =3D"Example"}

let one_s _ =3D (foo_s ())#x

let one_= t _ =3D (foo_t ()).x

let fac =3D
=C2=A0 let rec fac n =3D
=C2= =A0=C2=A0=C2=A0 let f =3D
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let rec f n a = =3D if n <=3D 1 then a else f (n - (one_s ())) (n * a)=C2=A0 in f (* cha= nge one_t to one_s or vice-versa *)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= in
=C2=A0=C2=A0=C2=A0 f n 1=C2=A0 in
=C2=A0 fac
let bench =3D
= =C2=A0 let rec bench n a =3D
=C2=A0=C2=A0=C2=A0 if n <=3D 0
=C2=A0= =C2=A0=C2=A0 then a
=C2=A0=C2=A0=C2=A0 else (let x =3D a && ((fa= c 20) =3D=3D (20 * (fac 19)))=C2=A0 in bench (n - 1) x)=C2=A0 in
=C2=A0 = bench
let test =3D bench 10000000 true
let main _ =3D test
<= div></snip>

If I run it with ocamlopt 4.05.0+= flambda and -O3, the version that uses one_s takes about 7.5s whereas the o= ne with one_t uses 0.35s. I know that object method lookup is more costly t= han records, of course. This particular case baffles me, though. Why is the= class not completely inlined?

Also as a related question, is = there a way to have the lookup semantics of methods without the open recurs= ion part? That is, can I have a class that consists of values, not methods?= It would love to have open tuples in some cases. For example, I'd like= to write a function that takes a tuple of any length, because it only need= s the first element.

thanks,

Christoph
=C2=A0
--94eb2c14c6846ebe76055c5bb745--