go icon indicating copy to clipboard operation
go copied to clipboard

time: optimize Parse and Time.Format for RFC3339

Open dsnet opened this issue 3 years ago • 6 comments

RFC3339 is the most common format to use (according to prior analysis, it accounts for 57% of formats; and that's only explicit calls to Format or Parse. It doesn't cover all the implicit cases that occur through MarshalText and UnmarshalText). We should optimize Parse and Time.Format to do a quick check for the RFC3339Nano or RFC3339 constants and hardcode the logic for that format. This would avoid the double parsing that currently occurs where we parse the format string to functionally run a virtual machine that then parses the input value.

dsnet avatar Jul 27 '22 18:07 dsnet

cc @ianlancetaylor @rsc

cherrymui avatar Jul 27 '22 20:07 cherrymui

Is it appropriate to offer my contribution here?

amarjeetanandsingh avatar Aug 03 '22 16:08 amarjeetanandsingh

Sure, your contribution is welcomed. See https://go.dev/doc/contribute for how to contribute to Go. Thanks.

cherrymui avatar Aug 03 '22 18:08 cherrymui

Happy to review.

dsnet avatar Aug 03 '22 18:08 dsnet

Sure. thanks @dsnet @cherrymui

I’ll be back shortly with initial implementation.

amarjeetanandsingh avatar Aug 05 '22 11:08 amarjeetanandsingh

Change https://go.dev/cl/421877 mentions this issue: time: optimize Format and Parse for RFC3339 and RFC3339Nano

gopherbot avatar Aug 07 '22 18:08 gopherbot

Change https://go.dev/cl/425100 mentions this issue: time: add fuzz test for Time.appendFormatRFC3339

gopherbot avatar Aug 22 '22 20:08 gopherbot

Change https://go.dev/cl/425197 mentions this issue: time: optimize Parse for RFC3339 and RFC3339Nano

gopherbot avatar Aug 23 '22 19:08 gopherbot