ThinkingDataAnalytics / go-sdk

ThinkingData SDK for Golang
Apache License 2.0
9 stars 13 forks source link

parseTime() allocs with more heap #14

Open feil3j opened 6 months ago

feil3j commented 6 months ago

Every time data is written to a file, parseTime() must be called, and the regexp in the method must be initialized. The more data is written, the greater the cumulative consumption. Suggest initializing regexp and processing it globally.

thinkingdata2_17132513372866

` func parseTime(input []byte) string {

var re = regexp.MustCompile(`"((\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2})(?:\.(\d{3}))\d*)(Z|[\+-]\d{2}:\d{2})"`)
var substitution = "\"$2 $3.$4\""

for re.Match(input) {
    input = re.ReplaceAll(input, []byte(substitution))
}
return string(input)

} `

feil3j commented 3 months ago

At the same time, repeated initialization of regexp results in more unnecessary CPU consumption.