Skip to content
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

Use a Parsers.jl-based parser implementation #80

Merged
merged 16 commits into from
Jun 14, 2023

Conversation

Drvi
Copy link
Collaborator

@Drvi Drvi commented Jun 13, 2023

This hooks into the floating point parsing machinery from Parsers.jl, where we also accumulate all the digits and note the effective exponent before we do "scaling" -- for FixedDecimals, the scaling means padding the backing integer with zeros or rounding them as necessary. This change should improve performance noticeably as we no longer allocate any strings during parsing.

RoundNearest rounding was redone during parsing to match the rounding behaviors on already parsed integers.

cc: @quinnj @NHDaly

@NHDaly NHDaly self-requested a review June 13, 2023 16:37
src/FixedPointDecimals.jl Outdated Show resolved Hide resolved
src/parse.jl Show resolved Hide resolved
src/parse.jl Show resolved Hide resolved
src/parse.jl Outdated Show resolved Hide resolved
src/parse.jl Outdated Show resolved Hide resolved
src/parse.jl Outdated Show resolved Hide resolved
src/parse.jl Show resolved Hide resolved
src/parse.jl Show resolved Hide resolved
src/parse.jl Show resolved Hide resolved
src/parse.jl Show resolved Hide resolved
src/parse.jl Show resolved Hide resolved
src/parse.jl Outdated
# all digits are zero
i = zero(T)
elseif backing_integer_digits < 0
# All digits are past our precision, no overflow possible
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm not understanding the comment quite right, but this makes it sound like it's backwards; I was expecting a phrase like "if any digits are past our precision, overflow is possible" or the inverse of "No digits are past our precision, so no overflow possible"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overflow is not possible here but inexact error is possible if we're not okay with rounding. In my mind overflow is when we try to parse "130" FD{Int8,0} and inexact would happen if we tried to parse "100.1" as FD{Int8,0}

src/parse.jl Show resolved Hide resolved
src/parse.jl Outdated Show resolved Hide resolved
Drvi and others added 5 commits June 14, 2023 09:46
Co-authored-by: Jacob Quinn <quinn.jacobd@gmail.com>
Co-authored-by: Jacob Quinn <quinn.jacobd@gmail.com>
Co-authored-by: Nathan Daly <nathan.daly@relational.ai>
src/parse.jl Outdated Show resolved Hide resolved
Copy link
Contributor

@quinnj quinnj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rock n' roll baby

Co-authored-by: Nick Robinson <npr251@gmail.com>
@Drvi Drvi requested a review from NHDaly June 14, 2023 13:01
Project.toml Outdated Show resolved Hide resolved
Comment on lines +67 to +69
function _divpow10!(x::T, code, pow, mode::RoundingMode) where {T}
return div(x, _shift(one(T), pow), mode), code
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not something for right now, but just sharing this because it's so super freaking cool:
#45

Todd came up with this approach to improve the performance of dividing by power of ten. Basically the idea is that you can skip the div, which is a very expensive operation, by instead multiplying by (2^64 / 10 / 2^64), and since you can precompute 2^64 / 10 as a constant, and then / 2^64 can be done by just a bit-shift, you can skip the divide. Really clever!

But I never managed to merge that PR, so............................. :)

I think we just leave that optimization aside here too, but it's fun and something cool to think about for the future! :)

Copy link
Member

@NHDaly NHDaly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry that I wasn't able to review today. I was pulled into an oncall investigation of a customer incident today, and it unexpectedly took up a bunch of my day. :[

I'm going to merge though, based on Jacob's review, and based on the preliminary review we did together over zoom! :) It does look like a much better approach.

Thanks all!

@NHDaly NHDaly merged commit 75c7226 into JuliaMath:master Jun 14, 2023
@Drvi Drvi mentioned this pull request Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants