bevyengine / bevyengine/bevy

Add display precision to diagnostics

Open
#6,033 4 comments 0 reactions 0 assignees View on GitHub
A-Diagnostics C-Usability D-Trivial
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## What problem does this solve or what need does it fill?

Diagnostics have no concept of display precision, so values for all diagnostics are displayed using a hard-coded static precision of `6` in the `LogDiagnosticsPlugin`:

https://github.com/bevyengine/bevy/blob/2b80a3f279d1273fbcface9e075637fe681a38d2/crates/bevy_diagnostic/src/log_diagnostics_plugin.rs#L65-L75

## What solution would you like?

A new field could be added to `bevy_diagnostic::Diagnostic`, `pub precision: usize`:

https://github.com/bevyengine/bevy/blob/2b80a3f279d1273fbcface9e075637fe681a38d2/crates/bevy_diagnostic/src/diagnostic.rs#L34-L42

## What alternative(s) have you considered?

Instead of handling value formatting manually in plugins with `format!`, `Diagnostic` could alternatively provide a formatting function to format values. A new field could be added to `bevy_diagnostic::Diagnostic`, `pub formatter: Arc String) + Send + Sync>`.

This approach would give maximum flexibility, but it does incur the (possibly minimal) runtime performance cost of dynamic dispatch.

## Additional context

This is relevant for a plugin I'm working on to dynamically visualize diagnostics.

https://github.com/sagan-software/bevy_diagnostic_visualizer

![image](https://user-images.githubusercontent.com/77758/191278606-4eceb8dd-a005-49ae-a805-4f97026a24b9.png)

Contributor guide

Open the contributing guide

Research direction

Start by reading crates/bevy_diagnostic/src/diagnostic.rs and crates/bevy_diagnostic/src/log_diagnostics_plugin.rs at the linked locations. Compare the proposed precision field with the formatter alternative, then trace how Diagnostic values are constructed and logged. Done means diagnostics can control their displayed precision without relying on the plugin's hard-coded value.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
observability
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.