neqo icon indicating copy to clipboard operation
neqo copied to clipboard

Examine usage and conversion of `f64` values in CUBIC code

Open omansfeld opened this issue 2 months ago • 1 comments

There are a bunch of f64 values in this code (not necessarily new with this PR, also before) that are inherently integers. For example, everything measured in bytes, etc. Could we re-examine this code to make sure we use integer types wherever possible, rather than f64? (At least if we can do so without more conversions.) - @larseggert

I looked at this when first starting the work on cubic. While all the byte values (cwnd, mss, acks etc.) are inherently usize they have to be multiplicated/divided with f64 values (e.g. all the constants that are not whole numbers).

I don't know if there is a smarter rust way to do this, but the only thing I can think of is using a divisor/divident approach instead, like in the reduce_cwnd function:

https://github.com/mozilla/neqo/blob/a75f3b58c889917fd28ec4a7d69ead8573eb8567/neqo-transport/src/cc/cubic.rs#L345-L351

I believe doing the conversions is more readable in comparison. That's why I initially abandoned the idea of doing something about it -- happy to hear of another way though if there is one.

Anyways, I will open another issue to track this, because I don't think it has to be part of this specific PR.

Originally posted by @omansfeld in https://github.com/mozilla/neqo/issues/2973#issuecomment-3346978910

omansfeld avatar Sep 29 '25 13:09 omansfeld

If all instances need to go into f64 math, we are done :-)

(Still wonder what the math came out with if we used something like https://docs.rs/fixed/latest/fixed/ like the Linux code does...)

larseggert avatar Sep 29 '25 14:09 larseggert