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

types: Dec.MarshalJSON now marshals as a normal decimal string #2506

Merged
merged 6 commits into from
Oct 21, 2018

Conversation

ValarDragon
Copy link
Contributor

Closes #2475

This implementation has sub-optimal efficiency, should re-use memory allocations in unmarshalling. However this is only called for UI purports, so not really a big deal if its a tiny bit slower.

  • Targeted PR against correct branch (see CONTRIBUTING.md)

  • Linked to github-issue with discussion and accepted design OR link to spec that describes this work.

  • Wrote tests

  • Updated relevant documentation (docs/) - no encoding docs atm

  • Added entries in PENDING.md with issue #

  • rereviewed Files changed in the github PR explorer


For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@ValarDragon
Copy link
Contributor Author

This is failing because we for some reason are MarshalJSON'ing decimals when used as parameter keys. That should be fixed in a separate PR.

types/decimal.go Outdated
bzWDec[len(bz)-10] = byte('.')
copy(bzWDec[len(bz)-9:], bz[len(bz)-10:])
}
return json.Marshal(string(bzWDec))
Copy link
Contributor

Choose a reason for hiding this comment

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

All this logic already exists using Decimal.String() - why are we not reusing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh woops, didn't see that lol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I think this implementation is more efficient (albeit harder to grok). I'd actually propose making a follow-up issue to compare efficiencies via benchmarks and converge on using one or the other.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yo - If I had to guess I'd say you're correct why don't we:

  • Replace the .String() code with your new updated logic
  • Use .String() in JSON Marshalling here
  • copy the old code into a #postlaunch issue for later benchmarking

:)

how does that sound?

@jackzampolin
Copy link
Member

Is this R4R?

@ValarDragon
Copy link
Contributor Author

Its ready to merge once I replace the current string implementation with my (more efficient looking) implementation written here.

@codecov
Copy link

codecov bot commented Oct 20, 2018

Codecov Report

Merging #2506 into develop will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff            @@
##           develop    #2506   +/-   ##
========================================
  Coverage    60.28%   60.28%           
========================================
  Files          150      150           
  Lines         8589     8589           
========================================
  Hits          5178     5178           
  Misses        3067     3067           
  Partials       344      344

types/decimal.go Outdated
copy(bzWDec[2+(10-len(bz)):], bz)
} else {
// len(bz) + 1 to account for the decimal point that is being added
bzWDec = make([]byte, len(bz)+1)
Copy link
Contributor

@cwgoes cwgoes Oct 21, 2018

Choose a reason for hiding this comment

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

Store len(bz) in a variable

types/decimal.go Outdated
bzWDec[0] = byte('0')
bzWDec[1] = byte('.')
// set relevant digits to 0
for i := 0; i < 10-len(bz); i++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

Store len(bz) in a variable

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

utACK

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