It seems the GetEncoding is not cheap to call since it have to compile regex. Creating a Tiktoken instance before every token calculation is not efficient. Therefore, if Tiktoken instance can be shared by multiple go routines, then we only need to create it once, which is more efficient.
It seems the
GetEncoding
is not cheap to call since it have to compile regex. Creating aTiktoken
instance before every token calculation is not efficient. Therefore, ifTiktoken
instance can be shared by multiple go routines, then we only need to create it once, which is more efficient.