Skip to content

Cleanup DateTime.t encoding in RowBinary#315

Merged
ruslandoga merged 4 commits intomasterfrom
improve-datetime-encoding
Apr 20, 2026
Merged

Cleanup DateTime.t encoding in RowBinary#315
ruslandoga merged 4 commits intomasterfrom
improve-datetime-encoding

Conversation

@ruslandoga
Copy link
Copy Markdown
Collaborator

@ruslandoga ruslandoga commented Apr 20, 2026

This PR also allows non-UTC timezones.

@ruslandoga ruslandoga changed the title Cleanup datetime encoding Cleanup DateTime.t encoding in RowBinary Apr 20, 2026
Comment thread bench/datetime_encode.exs
"now" => NaiveDateTime.utc_now()
"now" => DateTime.utc_now(),
"now in Tahiti" => DateTime.shift_zone!(DateTime.utc_now(), "Pacific/Tahiti")
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Operating System: macOS
CPU Information: Apple M2
Number of Available Cores: 8
Available memory: 8 GB
Elixir 1.19.5
Erlang 28.3
JIT enabled: true

Benchmark suite executing with the following configuration:
warmup: 2 s
time: 5 s
memory time: 0 ns
reduction time: 0 ns
parallel: 1
inputs: now, now in Tahiti
Estimated total run time: 28 s
Excluding outliers: false

Benchmarking to_gregorian with input now ...
Benchmarking to_gregorian with input now in Tahiti ...
Benchmarking to_unix with input now ...
Benchmarking to_unix with input now in Tahiti ...
Calculating statistics...
Formatting results...

##### With input now #####
Name                   ips        average  deviation         median         99th %
to_unix             9.53 M      104.99 ns  ±3061.80%          83 ns         208 ns
to_gregorian        8.73 M      114.60 ns  ±3495.58%          83 ns         167 ns

Comparison: 
to_unix             9.53 M
to_gregorian        8.73 M - 1.09x slower +9.61 ns

##### With input now in Tahiti #####
Name                   ips        average  deviation         median         99th %
to_unix             9.50 M      105.21 ns  ±3040.73%          83 ns         208 ns
to_gregorian        7.49 M      133.60 ns  ±5202.71%         125 ns         208 ns

Comparison: 
to_unix             9.50 M
to_gregorian        7.49 M - 1.27x slower +28.39 ns

"DateTime64(6) now in Tahiti" =>
{_time_unit = 1_000_000, DateTime.shift_zone!(DateTime.utc_now(), "Pacific/Tahiti")},
"DateTime64(9) now in Tahiti" =>
{_time_unit = 1_000_000_000, DateTime.shift_zone!(DateTime.utc_now(), "Pacific/Tahiti")}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Operating System: macOS
CPU Information: Apple M2
Number of Available Cores: 8
Available memory: 8 GB
Elixir 1.19.5
Erlang 28.3
JIT enabled: true

Benchmark suite executing with the following configuration:
warmup: 2 s
time: 5 s
memory time: 0 ns
reduction time: 0 ns
parallel: 1
inputs: DateTime64(3) now, DateTime64(3) now in Tahiti, DateTime64(6) now, DateTime64(6) now in Tahiti, DateTime64(9) now, DateTime64(9) now in Tahiti
Estimated total run time: 1 min 24 s
Excluding outliers: false

Benchmarking to_gregorian with input DateTime64(3) now ...
Benchmarking to_gregorian with input DateTime64(3) now in Tahiti ...
Benchmarking to_gregorian with input DateTime64(6) now ...
Benchmarking to_gregorian with input DateTime64(6) now in Tahiti ...
Benchmarking to_gregorian with input DateTime64(9) now ...
Benchmarking to_gregorian with input DateTime64(9) now in Tahiti ...
Benchmarking to_unix with input DateTime64(3) now ...
Benchmarking to_unix with input DateTime64(3) now in Tahiti ...
Benchmarking to_unix with input DateTime64(6) now ...
Benchmarking to_unix with input DateTime64(6) now in Tahiti ...
Benchmarking to_unix with input DateTime64(9) now ...
Benchmarking to_unix with input DateTime64(9) now in Tahiti ...
Calculating statistics...
Formatting results...

##### With input DateTime64(3) now #####
Name                   ips        average  deviation         median         99th %
to_gregorian       10.05 M       99.55 ns  ±5065.62%          83 ns         125 ns
to_unix             7.01 M      142.62 ns  ±3745.70%         125 ns         250 ns

Comparison: 
to_gregorian       10.05 M
to_unix             7.01 M - 1.43x slower +43.07 ns

##### With input DateTime64(3) now in Tahiti #####
Name                   ips        average  deviation         median         99th %
to_gregorian        7.29 M      137.24 ns  ±5284.51%         125 ns         209 ns
to_unix             7.01 M      142.71 ns  ±3873.81%         125 ns         250 ns

Comparison: 
to_gregorian        7.29 M
to_unix             7.01 M - 1.04x slower +5.47 ns

##### With input DateTime64(6) now #####
Name                   ips        average  deviation         median         99th %
to_gregorian       10.16 M       98.40 ns  ±4861.36%          83 ns         125 ns
to_unix             7.24 M      138.14 ns  ±2746.50%         125 ns         250 ns

Comparison: 
to_gregorian       10.16 M
to_unix             7.24 M - 1.40x slower +39.74 ns

##### With input DateTime64(6) now in Tahiti #####
Name                   ips        average  deviation         median         99th %
to_gregorian        7.28 M      137.27 ns  ±4949.95%         125 ns         209 ns
to_unix             7.11 M      140.66 ns  ±2833.48%         125 ns         250 ns

Comparison: 
to_gregorian        7.28 M
to_unix             7.11 M - 1.02x slower +3.39 ns

##### With input DateTime64(9) now #####
Name                   ips        average  deviation         median         99th %
to_gregorian        9.03 M      110.70 ns  ±3501.29%          84 ns         167 ns
to_unix             7.06 M      141.72 ns  ±2605.18%         125 ns         250 ns

Comparison: 
to_gregorian        9.03 M
to_unix             7.06 M - 1.28x slower +31.02 ns

##### With input DateTime64(9) now in Tahiti #####
Name                   ips        average  deviation         median         99th %
to_gregorian        7.03 M      142.28 ns  ±2563.82%         125 ns         250 ns
to_unix             6.98 M      143.34 ns  ±1095.14%         125 ns         250 ns

Comparison: 
to_gregorian        7.03 M
to_unix             6.98 M - 1.01x slower +1.06 ns

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Why is to_gregorian faster?

@ruslandoga ruslandoga merged commit c6d8cec into master Apr 20, 2026
3 of 5 checks passed
@ruslandoga ruslandoga deleted the improve-datetime-encoding branch April 20, 2026 20:06
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