-
Notifications
You must be signed in to change notification settings - Fork 4
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
Improvements : Idiomatic code #4
Comments
Hi, I don't think f64 is faster than f32. It is the same or slower. Also I believe there is no conversion f64 <-> f32 (I use everywhere f32). I found f64 only in performance.rs and it can be replaced by f32 easily :) |
If it is the same, I would argue that the added precision would be useful. |
The
|
with #5 merged, there are still some more low hanging fruit remaining, but not many. Next, I will address some function signatures, specifically their types . Hopefully this can enable more refactoring with less unnecessary copies or clones. Beyond that, I think breaking down large functions in |
Btw would you prefer PRs to be smaller(focusing on single functions or at most, files) or current level? |
this function only rounds floats to some number of digits after the point in the end of processing. I don't think that's good idea to add rust_decimals because of such functionality. |
current level is OK, no problem :) |
If it is only for output purposes, we might be able to use something like |
Seems to indicate that there was a regression. But it seems to have caused a drop in accuracy. I think it might have been apparent if I tested with the |
Aha... I believed we should just removed unreachable code, but in original version logic was changed - I didn't realize it. I left a question about actual accuracy in original PR. |
There are some small things that could be done, but I don't see any big things atm. The only big thing I had in mind is to write a wrapper around |
Re : #3
This codebase has been ported from Python and a lot of the design patterns could be improved to be more idiomatic rust code.
Such a move will make it easier to improve speed and maintainability, ensure correct operation from a rust point of view.
Some examples would be avoiding for loops, using matches instead of if chains etc.
Many require deeper consideration.
For example, this codebase has extensive use of
f32
. Unless using intrinsics,f64
are as fast as or faster thanf32
in rust.Moreover, trying to cast to and back for
f32
andf64
can harm performance and make it difficult to ensure correct code. For instance there are instances of exact compare between f32 and f64 variables, and this is very unlikely to operate in the intended way. If it is intended, it would be valuable to have documentation regarding that, suppressing relevant lints as well.However, if there is a need to maintain ABI compatibility or follow a specification it might be inevitable. Also, on-disk size could be a consideration.
In summary f32 vs f64 handling could serve as both idiomatic code and speed but only if done right.
I will try to prepare some PRs that change some things. Despite my best efforts, I am sure that many of my changes or views might be based on a flawed understanding of the code, so feel free to explain why things were done the way they were.
In such cases I will help with documentation.
The text was updated successfully, but these errors were encountered: