Skip to content

Fix json rendering of large osm ids #7096

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

imannamdari
Copy link

@imannamdari imannamdari commented Jan 12, 2025

Issue

Fix #7016

Tasklist

Requirements / Relations

Link any requirements here. Other pull requests this PR is based on?

Copy link
Contributor

@afarber afarber left a comment

Choose a reason for hiding this comment

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

@@ -54,7 +54,10 @@ template <typename Out> struct Renderer
// `fmt::memory_buffer` stores first 500 bytes in the object itself(i.e. on stack in this
// case) and then grows using heap if needed
fmt::memory_buffer buffer;
fmt::format_to(std::back_inserter(buffer), FMT_COMPILE("{:.10g}"), number.value);
if (static_cast<std::uint64_t>(number.value) == number.value)
fmt::format_to(std::back_inserter(buffer), FMT_COMPILE("{}"), static_cast<std::uint64_t>(number.value));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the if/else block really needed? Can't a single line below handle the big integer number up to 18446744073709551615 (which is 2^64-1)?

fmt::format_to(std::back_inserter(buffer), FMT_COMPILE("{}"), static_cast<std::uint64_t>(number.value));

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, nevermind, I see that it would break the fractional numbers

Copy link
Author

Choose a reason for hiding this comment

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

Exactly. For floating-points there gonna be problems.
The previous approach implemented before this commit can be found here (and it works fine):

void operator()(const Number &number)

A more robust solution could be separating floats from integers. Instead of Number struct, we can have Float and Integer structs for example. Each with their own json rendering.
However, that's a significant change! :D
If you agree with this approach (separating floats from integers), I can work on it in another pull request.

Copy link
Contributor

@afarber afarber Jan 25, 2025

Choose a reason for hiding this comment

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

Dear @DennisOSRM and @SiarheiFedartsou now that CI build is working again, could you please consider merging this fix by @imannamdari ?

In the past week I have tested his fix with map matching and it really seems to fix the problem with large OSM node/way ids.

And please consider adding a new git tag v5.28.1 after the merge?

Because the current tag v5.27.1 is already three years old and it would be nice to set a newer stable source code "checkpoint" for all users.

Copy link
Collaborator

Choose a reason for hiding this comment

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

new release coming soon

Copy link
Contributor

Choose a reason for hiding this comment

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

I have proposed a solution with separate treatment of OSM ids as uint64_t in #7142.

Copy link
Author

Choose a reason for hiding this comment

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

@DennisOSRM whats your opinion? should we temporarily change precision from 10 to 11 to solve large osm ids rendering, and then working on separating json number struct to two integer and double structs for more scalable solution?

That's a workaround that would buy some time to do the other changes I think. Any more code changes necessary to do it?

It seems that, for now, the maximum osm id is around 13,000,000,000. I increased the precision from 10 to 12, which should buy us a few more years.

After merging this, the bug should no longer appear in our upcoming release. In the meantime, we can work on @MarcelloPerathoner 's PR to implement a better solution for this issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem with this patch is that it changes the format for all numbers. It adds even more digits where 9 digits should be amply sufficient. And this still doesn't fix the problem for people that use high IDs for private extensions.

Copy link
Author

Choose a reason for hiding this comment

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

f 9 digits are enough to represent a number, it will produce 9 digits (it won’t expand it to 12 digits). This is the difference between .g and .f (see the tests).

Hmm, I didn’t know about private extensions. Previously, you mentioned that as a short-term solution, instead of casting, we should simply increase the precision from 10 to 11. If this increase doesn’t solve the issue, and casting is an expensive operation (which I personally don’t believe it is, since I deployed this code in production with over 10k RPS, and the CPU usage is no different from the without-cast solution), then we don’t have a viable short-term solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

Private extensions are mentioned here: #7069

@imannamdari imannamdari force-pushed the fix-large-osmids-json-rendering branch from 927eef1 to c398a2a Compare April 3, 2025 20:18
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.

Json_render is not accurate for osm node ID
4 participants