From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: * X-Spam-Status: No, score=1.8 required=3.0 tests=BAYES_50,TO_NO_BRKTS_PCNT autolearn=no autolearn_force=no version=3.4.5-pre1 X-Received: by 2002:a37:6491:: with SMTP id y139mr962654qkb.483.1616432546169; Mon, 22 Mar 2021 10:02:26 -0700 (PDT) X-Received: by 2002:a25:1883:: with SMTP id 125mr565113yby.465.1616432545903; Mon, 22 Mar 2021 10:02:25 -0700 (PDT) Path: eternal-september.org!reader02.eternal-september.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 22 Mar 2021 10:02:25 -0700 (PDT) Injection-Info: google-groups.googlegroups.com; posting-host=73.2.251.187; posting-account=JSxOkAoAAADa00TJoz2WZ_46XrZCdXeS NNTP-Posting-Host: 73.2.251.187 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <07a56dcc-9e17-49b2-a980-3a5a2d265cedn@googlegroups.com> Subject: Performance of records with variant parts From: John Perry Injection-Date: Mon, 22 Mar 2021 17:02:26 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:61626 List-Id: Hello all I encountered a significant penalty when using a record with variant parts = in gnat community edition, on both MacOS and Linux. Suppose I have the foll= owing. (Kind of long, sorry.) | type Object_Type is ( Sphere, Plane, None ); | type Surface_Type is ( Shiny, Checkerboard ); | type Thing_Type(kind: Object_Type :=3D None; surface: Surface_Type :=3D S= hiny) | is record | case kind is | when None =3D> | null; | when Sphere =3D> | radius2: Long_Float :=3D 0.0; | center: Vector; | when Plane =3D> | offset: Long_Float :=3D 0.0; | norm: Vector; | end case; | end record; Noticing that the fields are actually the same types, but different names, = I also tried this: | type Thing_Type is record | Kind: Object_Type :=3D None; | Surface: Surface_Type :=3D Shiny; | Size: Long_Float :=3D 0.0; | Pos: Vector; | end record; This second version doesn't seem a good idea, but compiled output runs 15-3= 0% faster. As far as I can tell***, it's related to this test which gets ca= lled ~3 million times: | case obj.kind is | when Sphere =3D> | -- do stuff | when Plane =3D> | -- do other stuff | when None =3D> | null; | end case; Is there a reason that the record with variant parts runs so much slower? I= can make the complete source available if need be. john perry ***"as far as I can tell": gprof stated at one point that this procedure s= ucks up most of the time; it's one of only two places where the discriminan= t is evaluated, and it's the only one that gets called A LOT; and this one = change makes for the difference in performance.