Uh oh!
There was an error while loading. Please reload this page.
First round of perf improvements for tiktoken - #7012
Conversation
stephentoub
commented
Feb 17, 2024
cc: @tarekgh |
| while (true) | ||
| { | ||
| string? line = reader.ReadLine(); | ||
| string? line = useAsync ? |
There was a problem hiding this comment.
This is more of a reliability/scalability fix rather than throughput. The asynchronous creation code path and the synchronous creation code path were both sharing this routine, which resulted in the asynchronous code path doing synchronous I/O (on a network stream). Now the async path does async and the sync path does sync, still sharing this same routine.
There was a problem hiding this comment.
Why we don't always do async operation here regardless if the code is coming from sync or async callers?
There was a problem hiding this comment.
Because if this is async, a sync caller will be forced to block this thread until the operation completes. The operation could easily require a thread pool thread to complete, yet if this is on a thread pool thread, it'd be blocking one of the very resources needed to make forward progress. The thing less scalable than sync I/O is sync-over-async I/O.
There was a problem hiding this comment.
But I thought you wanted to have a constructor which execute async too. no?
There was a problem hiding this comment.
I do (a factory method rather than a ctor, but yeah). It will use this.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@## main #7012 +/- ##
=======================================
Coverage 68.80% 68.81% =======================================
Files 1258 1258 Lines 250652 250643 -9 Branches 25602 25606 +4 =======================================
Hits 172472 172472 + Misses 71548 71546 -2 + Partials 6632 6625 -7
Flags with carried forward coverage won't be shown. Click here to find out more.
|
tarekgh
commented
Feb 18, 2024
| private static unsafe int GetUtf8Bytes(ReadOnlySpan<char> source, Span<byte> destination) | ||
| { | ||
| #if NETCOREAPP |
There was a problem hiding this comment.
We already have .netstandard and .netcoreapp cs files in the project. Will be good to move this code into these twp files and avoid using #if.
| { | ||
| if ((uint)utf8ByteCount + (uint)tokenBytes.Length > (uint)utf8Bytes.Length) | ||
| { | ||
| ArrayPoolGrow(ref utf8Bytes, ref arrayPoolArray, utf8ByteCount + tokenBytes.Length); |
There was a problem hiding this comment.
never mind, it is not going to grow more in this path.
tarekgh
left a comment
There was a problem hiding this comment.
This is amazing. Thanks a lot @stephentoub.
I'll merge this and I can do the #if cleanup things in another PR.
Before:
After: