Repository navigation
Conversation
vxc calls vx_cancel_off before each call of a Drop impl's drop, and vx_cancel_on after it. With a release runtime, these two calls took more than half of the time of the solver written in Vx. It drops BigInt and Rational values in its inner loops. Three changes make them cheaper. A drop gets the same deadline as before. - The current mark and the scopes with a deadline are one thread-local value. So each call reads the state of the thread once, not up to five times. - The outermost drop on a thread with no tasks block and no other scope keeps its scope in a small thread-local value with no destructor. A drop inside it that shares its scope only adds 1 to a count. Each other call moves the scope into the full state first. - That drop keeps the raw reading of the coarse clock. Only a drop that needs its deadline turns the reading into nanoseconds. On macOS, the runtime reads the ratio of clock ticks to nanoseconds once. clock_gettime_nsec_np asked for it at each call. The new test a_wait_in_a_drop_can_take_up_to_its_time_limit.vx checks that a drop can wait until its deadline. The tests before it checked only that a drop gives up at its deadline. Part of #4583
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #4583.
What changes
vxc calls
vx_cancel_offbefore each call of aDropimpl'sdrop, andvx_cancel_onafter it. They give the drop its deadline (F6a indocs/discussions/waiting_tasks_channels_and_task_errors.md). With a release runtime, these two calls took more than half of the time of the solver written in Vx. It dropsBigIntandRationalvalues in its inner loops. Each drop of aVec,String,BoxorArcmakes the same two calls.Three changes in
stdlib/rust_core/src/ffi/tasks.rsandwait.rsmake them cheaper. A drop gets the same deadline as before.MARKS. Each call reads the state of the thread once, not up to five times.tasksblock and no other scope. There, the outermost drop keeps its scope inOUTER_DROP, a small thread-local value with no destructor. A drop inside it that shares its scope only adds 1 to a count. Each other call goes throughmarks(), which moves that scope intoMARKSfirst.clock_gettime_nsec_npasked for it at each call.Measurements
The solver written in Vx, on 340 queries:
ifstatements or 12matchstatements in a rowtests/solver/queries/that are linearA program built with
vxc -O2fromrun_corpus.vxruns them all, one after the other. I linked it 5 times, each time with a different runtime built withcargo build --release. The answers are the same in each run.caffeinate -dimsstd::algo::smtofmainat 414bb29, compiled withvxc -O2Total time of each group, in ms: the median of 5 runs, with the fastest and the slowest run.
mainvx_cancel_offandvx_cancel_onemptyThe last row is a floor: it keeps the calls, but they do nothing. Each of the 340 queries is faster with this PR. Per query,
maintakes this long, in times the time with this PR:The 4 slowest nonlinear queries are from
llama2.vx. Each took about 204 ms withmain, and takes about 113 ms with this PR.Where the gain comes from
Each row adds one change to the row above it. The first two rows with a change keep the clock code of
main.mainLimits
Commands
Tests
tasks.rsgets three unit tests ofOUTER_DROP. Drops in it leaveMARKSempty. A read of the deadline moves the scope intoMARKS. A drop in atasksblock puts its mark aside inMARKS.a_wait_in_a_drop_can_take_up_to_its_time_limit.vxis new. Adropsleeps for 0.3 s, andsleepmust givetrue: the whole time passed. It drops a value in the main code, in anotherdrop, and in a task. The tests before it checked only that a drop gives up at its deadline.I broke the code in 11 ways, one at a time, and each made a test fail:
OUTER_DROPmarks()does not move the scope ofOUTER_DROPOUTER_DROPalso with a mark currentOUTER_DROPis not used again after the first call ofmarks()OUTER_DROPhas no lag of the coarse clockthe_deadline_of_a_drop_is_its_limit_from_now_or_a_little_laterOUTER_DROPa_drop_in_a_drop_with_a_shorter_limit_gets_an_earlier_deadlinevx_cancel_ondoes not count downOUTER_DROPdrops_in_the_outermost_drop_share_its_scope_with_no_scope_in_marksthe_coarse_clock_is_never_ahead_and_never_behind_by_more_than_its_lagand the deadline testOUTER_DROPhas no limit.vxtest, in the main code and in a drop in a drop, in each of its 3 RUN linesMARKShas no limit.vxtest, in the task, in each of its 3 RUN linesWith no limit on the deadline of
OUTER_DROP, the 6 older tests of drops that wait intests/backend/pass/still passed. They check only that a drop gives up.