From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-3.2 required=3.0 tests=BAYES_00,NICE_REPLY_A, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!news.szaf.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: does a safer language mean it is slower to run? Date: Thu, 8 Jun 2023 09:57:14 +0300 Organization: Tidorum Ltd Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net rlAlf82gORVaBHUu8zCFUAZfWkFXxn7llIy/KJoAgq6GSPTpXk Cancel-Lock: sha1:dOb37qriBWf9C5dMPr3cV0J6ETw= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Content-Language: en-US In-Reply-To: Xref: news.eternal-september.org comp.lang.ada:65300 List-Id: On 2023-06-08 6:55, Nasser M. Abbasi wrote: > Some folks in this thread > > https://discourse.julialang.org/t/comparison-of-rust-to-julia-for-scientific-computing/78508 > > "I’m not an expert, but my feeling is that Rust is a “safer” language, > which to me means it must be slower." > > etc.. > > Some in that thread seem to argue that a safer language > will/could be slower than otherwise. > > Since Ada is known to be one of the safest languages, > do others here feel there is any truth to this? > > I thought that by having more type information in the language, > the compile will be able to make more optimizations (because it > know more), and hence the generated code should actually be > faster, not slower with a language that is less safe? > > I am not a compiler expert but what do others here think? If a language needs run-time checks to ensure safety, those checks usually take some time, making for slower execution. If a language has a type system and compilation-time (legality) rules such that the compiler can prove that some run-time checks are not needed, that reduces or eliminates the slow-down. This is the case for Ada. The effect of type information on optimization is harder (at least for me) to understand. If the type information lets the compiler assume that some objects are not aliased, that can help optimization because more computation can be done in registers alone, without using main memory. This applies to Ada, but also applies to standard C, for example, although some people use non-standard C features (compiler options) to negate this. However, when comparing the "speed" of two languages and their two implementations I think that the implementations usually matter more than the languages.