-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A [no overflow check] compiler direective #14828
Comments
Having implemented a bunch of PRNG, I understand the appeal. That being said, this is just a few |
In Rust you can do this:
to achieve turning off bounds checking. Again, I'm not concerned with the semantics, I want the same affect. I'm not aware that Rust even has the equivalent of individual So if that would be semantically more appealing I would be all for it. |
I didn't know Rust disabled checks inside |
This is doubtful. If a single operator (e.g. I relate to the sentiment that operators with |
No, no, that is not what I meant. I misspoke if you took it that way. I'm not proposing dual meanings of the I am not proposing any change to the handling of So philosophically and operationally nothing that already exists changes. This will improve the writing|reading of code, and aide in code testing too. Again, nothing proposed here changes the thinking and responsibilities of users to write I think it's undeniable, to a code writer and reader, that something like this is more desirable:
than this:
Two simple lines of code to add, versus changes to 4 individual operators (and this is a very simple real example). So please focus the discussion|understanding of this proposal on how it will make users |
Could you clarify this phrase from the OP then?
I read that as inside a block of code annotated as (this aspect is only a minor detail of course, so no need to elaborate extensively until there's a consensus on the general proposal) |
I was thinking faster than I could write. If an overflow occurs within an From personal experience, most algorithms work over well defined number spaces (like modulo arithmetic) and have predefined min|max data ranges|types. You don't start out using This is how I write my Rust code, when I want to be as fast as possible within a code base. Most stuff occurs once, or infrequently, and won't affect (measurable) performance anyway, so you don't worry about it. But stuff occurring inside loops (like the As math in most realworld algorithms perform dozen of I wasn't around to follow the discussions in Rust around this, but the Rust devs are some of the most annal people around in making their standard code base be Since Rust and Crystal both use |
Based on thoughts derived from this forum thread:
https://forum.crystal-lang.org/t/there-is-a-way-to-optimize-this-program/6947/50
I'm proposing creating a compiler directive something like
[no overflow check]
to tell the compiler to not perform math overflow checks in the following method. Or even a finer tuned directive to not perform overflow checks around blocks of code.So given code like this, where you have to use individual
&+|&*
operators:You could instead do something like this:
This makes the code much, much easier to write|read, and explicitly expresses to anyone reading it what's happening.
Based on the forum discussion of the potential performance improvements by eliminating
overflow checks
I modified some old code, and saw some significant performance improvement using the&+|&*
operators. However, the code become, IMO, unnecessarily longer and verbose.Here is an example of actual code modified to use the
&+|&*
operators:None of the math here requires
overflow checks
, and having to use the&x
operators all over the place just seems an unnecessary burden (besides being ugly) to place on programmers.This would be so much easier|shorter|better to write.
So now, you just write one set of code to establish correctness, and use a compiler directive to increase performance. If you then need to do overflow checking on some operation(s) for correctness, you can do it on just them by using the
&x
operators inside the code.Since I primarily do numerical algorithmic programming, this would make my life so much easier. I could easily tests methods to see which would benefit from this using a single compiler directive, and eliminates having to write an altered version of each method to test.
I hope you see the utility of adding this feature to Crystal. I will make it so much easier for people to get the highest performance they can get from Crystal when they really need|want it.
The text was updated successfully, but these errors were encountered: