8000 Update time crate to 0.3.5 by jamessan · Pull Request #5761 · alacritty/alacritty · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Update time crate to 0.3.5 #5761

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

Merged
merged 1 commit into from
Jan 13, 2022
Merged

Conversation

jamessan
Copy link
Contributor
@jamessan jamessan commented Jan 9, 2022

Due to unsoundness issues (c.f., time-rs/time#380 and time-rs/time#293), determining the local timezone can only happen while single-threaded.

Determine the timezone early in startup and apply the offset to the UTC timestamp before formatting.

Copy link
Member
@chrisduerr chrisduerr left a comment

Choose a reason for hiding this comment

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

This also switches the timestamp format from local timezone to UTC since getting the local timezone is fallible. Rather than complicating the code with a fallback to UTC, just use UTC all the time.

You make it sound like this is somehow an improvement, but the code is significantly more complex and performs worse. Is the motivation solely to bump the version number of the dependency?

@jamessan
Copy link
Contributor Author
jamessan commented Jan 9, 2022

Is the motivation solely to bump the version number of the dependency?

The main motivation is bumping the version, yes. 0.1 is in maintenance mode and rather than add more things that depend on it to Debian, I thought I would propose a change to update to the maintained time version.

the code is significantly more complex

I didn't think a different way of describing the format would be considered significantly more complex. I see that RFC3339 format is one of the well-known formats, so that line could be changed to

let now = OffsetDateTime::now_utc().format(&well_known::Rfc3339).unwrap();

and performs worse

The parsing of the format string is done at compile time, and the actual formatting of the time object to the resulting output string is, from what I can tell, the same between 0.1 and 0.3.

Is there a general performance difference between the two versions of the crate or was this something measured? If it's the latter, I would be glad to know how I should be verifying such issues.

@chrisduerr
Copy link
Member

The main motivation is bumping the version, yes. 0.1 is in maintenance mode and rather than add more things that depend on it to Debian, I thought I would propose a change to update to the maintained time version.

Fair enough, that's probably one of the best arguments one could have come up with.

While version 0.1 of the time crate might be in "maintenance mode", which also is perfectly fine since Alacritty does not need any new features, afaik a lot of crates still depend on it. I think the significant majority still depends on 0.2 iirc. Do you have any insight on the distribution of crates relevant for Debian packaging that depend on the different versions? Is the majority actually on 0.3?

I didn't think a different way of describing the format would be considered significantly more complex.

While neither of them are monumentally complicated implementations, one certainly is more complex than the other. Especially if we consider that the strftime format is very well known and can be easily edited and reviewed by anyone while I (and likely most other people) have absolutely no clue about the new DSL used by time 0.3.

The parsing of the format string is done at compile time, and the actual formatting of the time object to the resulting output string is, from what I can tell, the same between 0.1 and 0.3.

Is there a general performance difference between the two versions of the crate or was this something measured? If it's the latter, I would be glad to know how I should be verifying such issues.

Excuse my impreciseness here, my comment about performance was not actually about performance, but about the way it performs. You've mentioned it's switched from local time to UTC time which is a significant UX regression as far as I'm concerned.

I see that RFC3339 format is one of the well-known formats, so that line could be changed to

Correct me if I'm wrong, but isn't that format "1985-04-12T23:20:50.52Z"? If so that's inferior to our current format both in readability and preciseness (which has been significant with some issues in the past).

@jamessan
Copy link
Contributor Author
jamessan commented Jan 9, 2022

Do you have any insight on the distribution of crates relevant for Debian packaging that depend on the different versions? Is the majority actually on 0.3?

From a quick glance, it looks like we only have a few crates depending on time at all. 1 was the impetus for packaging 0.3, 4 still use 0.1, 1 has dropped the dependency upstream but we haven't pulled that in yet, and 1 has ported to 0.2.

Especially if we consider that the strftime format is very well known and can be easily edited and reviewed by anyone while I (and likely most other people) have absolutely no clue about the new DSL used by time 0.3.

Fair. I had never actually encountered the abbreviation formats you were using before, even though I'm familiar with the classic strftime formats.

You've mentioned it's switched from local time to UTC time which is a significant UX regression as far as I'm concerned.

:) For most things I'm involved in, times are expected to be in UTC so that biased me. It is possible to get the local timezone with time 0.3.5 ... with some caveats, which is why it's fallible. I figured for a logging system, being infallible was more important.

Correct me if I'm wrong, but isn't that format "1985-04-12T23:20:50.52Z"? If so that's inferior to our current format both in readability and preciseness (which has been significant with some issues in the past).

Yes, the T is present between the data and time. The fractional seconds do show up to 9 digits of precision, but it's not at a fixed width.

Rather than using the DSL, there's a trait that can be implemented to format the time...


On the balance, it seems like this isn't a change that fits. Feel free to close it, if so.

The previous attempt I found to update to 0.2 solely mentioned the mass of dependencies as an issue, so when I saw that wasn't an issue with 0.3 I thought I'd give it a shot.

If nothing else, I learned a bit more than I wanted about dealing with time in Rust and I have something to point to if there are questions about updating the crate in the future.

@chrisduerr
Copy link
Member

:) For most things I'm involved in, times are expected to be in UTC so that biased me. It is possible to get the local timezone with time 0.3.5 ... with some caveats, which is why it's fallible. I figured for a logging system, being infallible was more important.

I'd assume we're not talking about sporadic failure here? So it shouldn't be that big of a problem. And failure should of course be handled and mitigated.

But these kinds of issues are exactly why I haven't migrated in the past, with the 0.1 crate our "ideal" solution was straight-forward to implement without ever having to read any documentation, getting the same exact behavior with 0.3 is just a headache. Of course one could go for all sorts of compromises, but to me that just seems rather unfortunate for something that should be so simple (and has been with 0.1 of the crate).

Yes, the T is present between the data and time. The fractional seconds do show up to 9 digits of precision, but it's not at a fixed width.

That surprises me, but I guess the RFC does suggest it's "at least 1" digit, not exactly two. Good to know though, thanks.

Rather than using the DSL, there's a trait that can be implemented to format the time...

Certainly all of that is possible and one of these things can likely be used to migrate in this PR. I've just been holding off until now because I'm rather frustrated with time's API progression.

On the balance, it seems like this isn't a change that fits. Feel free to close it, if so.

It's probably mostly an issue of just sooner or later accepting the disadvantages of the new API and moving on. I personally don't need any migration, I'm perfectly fine with keeping it as 0.1 forever, but as you've pointed out sooner or later distributions packaging Alacritty would likely prefer having more recent dependencies. So since that gives us a good reason to upgrade, it probably makes sense to do so.

I'd say the biggest issue with this PR is the UTC time. I don't like to confuse users looking at logs and I don't particularly like to be confused myself. Since this is an application expected to run on the user's desktop, not some kind of server that might be in a different timezone, I see no good reason why we would have our logs in UTC format. So if you can get that figured out while keeping our current format, I think we can begrudgingly ignore the other issues.

@jamessan
Copy link
Contributor Author

I'd say the biggest issue with this PR is the UTC time. I don't like to confuse users looking at logs and I don't particularly like to be confused myself.

I've addressed this by caching, via lazy_static, the local TZ at startup and then using that offset to adjust the timestamp when logging.

@jamessan jamessan force-pushed the update-time branch 2 times, most recently from 1e37ab3 to d3ffa0f Compare January 12, 2022 05:00
logfile,
stdout,
event_proxy: Mutex::new(event_proxy),
tz_offset: UtcOffset::current_local_offset().unwrap(),
Copy link
Member

Choose a reason for hiding this comment

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

I'd like an expect rather than unwrap here.

let now = OffsetDateTime::now_utc()
.to_offset(tz_offset)
.format(format_description!(
"[year]-[month]-[day] [hour repr:24]:[minute]:[second].[subsecond digits:9]Z"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"[year]-[month]-[day] [hour repr:24]:[minute]:[second].[subsecond digits:9]Z"
"[year]-[month]-[day] [hour repr:24]:[minute]:[second].[subsecond digits:9]"

Not UTC anymore.

fn create_log_message(record: &log::Record<'_>, target: &str, tz_offset: UtcOffset) -> String {
let now = OffsetDateTime::now_utc()
.to_offset(tz_offset)
.format(format_description!(
Copy link
Member

Choose a reason for hiding this comment

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

If you move this format_description! out of the parameter, it'll clean stuff up:

    let time_format = format_description!(
        "[year]-[month]-[day] [hour repr:24]:[minute]:[second].[subsecond digits:9]"
    );
    let now = OffsetDateTime::now_utc().to_offset(tz_offset).format(time_format).unwrap();

Due to unsoundness issues (c.f., time-rs/time#380 and time-rs/time#293),
determining the local timezone can only happen while single-threaded.

Determine the timezone early in startup and apply the offset to the UTC
timestamp before formatting.
Copy link
Member
@chrisduerr chrisduerr left a comment

Choose a reason for hiding this comment

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

Looks good, thanks.

@chrisduerr chrisduerr merged commit 1c9fa73 into alacritty:master Jan 13, 2022
@jamessan jamessan deleted the update-time branch January 23, 2022 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0