From mboxrd@z Thu Jan 1 00:00:00 1970 X-Received: by 2002:a05:6214:4b12:b0:66c:fe6b:ff4d with SMTP id pj18-20020a0562144b1200b0066cfe6bff4dmr317325qvb.6.1698253318929; Wed, 25 Oct 2023 10:01:58 -0700 (PDT) X-Received: by 2002:aca:240a:0:b0:3b2:e46e:448c with SMTP id n10-20020aca240a000000b003b2e46e448cmr5916815oic.3.1698253318667; Wed, 25 Oct 2023 10:01:58 -0700 (PDT) Path: eternal-september.org!news.eternal-september.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 25 Oct 2023 10:01:58 -0700 (PDT) In-Reply-To: Injection-Info: google-groups.googlegroups.com; posting-host=49.184.135.245; posting-account=L5wwzgoAAAAfQcZzW8eLJKqyFogVIeWA NNTP-Posting-Host: 49.184.135.245 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <868c2fa0-9480-45e7-899f-28c8993aafaan@googlegroups.com> Subject: Re: does a safer language mean it is slower to run? From: robin vowels Injection-Date: Wed, 25 Oct 2023 17:01:58 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 3855 Xref: news.eternal-september.org comp.lang.ada:65809 List-Id: On Thursday, 8 June 2023 at 16:57:17 UTC+10, Niklas Holsti wrote: > On 2023-06-08 6:55, Nasser M. Abbasi wrote:=20 > > Some folks in this thread=20 > >=20 > > https://discourse.julialang.org/t/comparison-of-rust-to-julia-for-scien= tific-computing/78508=20 > >=20 > > "I=E2=80=99m not an expert, but my feeling is that Rust is a =E2=80=9Cs= afer=E2=80=9D language,=20 > > which to me means it must be slower."=20 > >=20 > > etc..=20 > >=20 > > Some in that thread seem to argue that a safer language=20 > > will/could be slower than otherwise.=20 > >=20 > > Since Ada is known to be one of the safest languages,=20 > > do others here feel there is any truth to this?=20 > >=20 > > I thought that by having more type information in the language,=20 > > the compile will be able to make more optimizations (because it=20 > > know more), and hence the generated code should actually be=20 > > faster, not slower with a language that is less safe?=20 > >=20 > > I am not a compiler expert but what do others here think? . > If a language needs run-time checks to ensure safety, those checks=20 > usually take some time, making for slower execution.=20 . Some language features need run-time checks. These checks cannot be carried out at compile time. . PL/I has some features that require run-time checks. When the computer hardware has certain facilities, that support does not take extra execution= time. For example, floating-point overflow and integer overflow are detected by t= he hardware on the IBM S/360 and subsequent machines including up to the lates= t System z. Such detections cause an interrupt that can be handled by the PL= /I program. On the PC, integer overflow can cause an interrupt. . > If a language has a type system and compilation-time (legality) rules=20 > such that the compiler can prove that some run-time checks are not=20 > needed, that reduces or eliminates the slow-down. This is the case for Ad= a.=20 . Range is not one of them. . > The effect of type information on optimization is harder (at least for=20 > me) to understand. If the type information lets the compiler assume that= =20 > some objects are not aliased, that can help optimization because more=20 > computation can be done in registers alone, without using main memory.=20 > This applies to Ada, but also applies to standard C, for example,=20 > although some people use non-standard C features (compiler options) to=20 > negate this.=20 >=20 > However, when comparing the "speed" of two languages and their two=20 > implementations I think that the implementations usually matter more=20 > than the languages.