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 float32 when lossless for float64 #365

Closed
wants to merge 2 commits into from

Conversation

klauspost
Copy link
Collaborator

When a float64 can be fully represented as a float32, use that instead.

Encoding is backwards compatible with existing reader. AppendFloat64Only is made available to unconditionally write a float64.

Micro-benchmarks are not great:

BenchmarkAppendFloat64Only-32    	511061935	         2.324 ns/op	3442.55 MB/s	       0 B/op	       0 allocs/op
BenchmarkAppendFloat64-32    	136697270	         8.704 ns/op	 919.08 MB/s	       0 B/op	       0 allocs/op

But microbenchmarks are micro-benchmarks. We take a much bigger cost on AppendInt64 and other integer functions.

We could make it opt-in, but that would make it pretty much unused.

When a float64 can be fully represented as a float32, use that instead.

Encoding is backwards compatible with existing reader. `AppendFloat64Only` is made available to unconditionally write a float64.

Micro-benchmarks are not great:

```
BenchmarkAppendFloat64Only-32    	511061935	         2.324 ns/op	3442.55 MB/s	       0 B/op	       0 allocs/op
BenchmarkAppendFloat64-32    	136697270	         8.704 ns/op	 919.08 MB/s	       0 B/op	       0 allocs/op
```

But microbenchmarks are micro-benchmarks. We take a much bigger cost on `AppendInt64` and other integer functions.

We could make it opt-in, but that would make it pretty much unused.
klauspost added a commit to klauspost/msgp that referenced this pull request Sep 29, 2024
Add `//msgp:compactfloats` file directive, that will store float64 as float32, if it can be done so losslessly.

Boring, but correct replacement of tinylib#365
@klauspost klauspost closed this Sep 29, 2024
@klauspost
Copy link
Collaborator Author

Replaced by #366

@klauspost klauspost deleted the float64-to-32 branch September 29, 2024 12:20
klauspost added a commit that referenced this pull request Sep 30, 2024
Add `//msgp:compactfloats` file directive, that will store float64 as float32, if it can be done so losslessly.

Boring, but correct replacement of #365
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.

1 participant