Repository navigation
Look up getLibraryApi's boundary roots by hash, and emit id tables in ascending order - #41
Merged
Merged
Conversation
… ascending order A getLibraryApi request names each file of a wheel as a root, and is_external compared every class's file with every root through Path::starts_with. Keep the roots in a hash set and look up the file's ancestors instead. Serialize each result once into a RawValue rather than through a serde_json::Value tree. The Value tree had sorted every object's keys, so tables keyed by id are now BTreeMaps: clients read them in arrival order, and a response stays byte-identical across processes.
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.
A
getLibraryApirequest for transformers 5.26.0 takes 9.9 s of CPU, and 29% of it goes to deciding whether each class lies inside the request's roots. The request names every one of the wheel's 2,979 files as a root, andis_externalcompared a class's file with each of them throughPath::starts_with, for every class literal and generic alias the registry builds.CPU of v1.0.3 and this branch in ms, both built locally with identical flags, median of 5 interleaved runs:
getLibraryApitransformers (2,979 files)getLibraryApiopenai (1,877 files)getLibraryApimypy (1,097 files)getLibraryApisqlalchemy (257 files)getLibraryApipydantic (106 files)getTypesfor each of fastapi's 1,233 filesPeak RSS drops as well, from 1,577 MB to 1,405 MB for transformers. Every response parses to the same JSON as v1.0.3's.
What changes
Boundary::UnderRootsholds anFxHashSet. A file is inside the boundary when one of its ancestors, itself included, is in the set, so each call costs the path's depth rather than the number of roots.JsonRpcResponse::successserializes its result once into aRawValue. It no longer builds aserde_json::Valuetree for every response, which is where thegetTypesgain above comes from.Tables keyed by id come out in ascending order
Serializing through
Valuesorted every object's keys, so v1.0.3 wrotetypesandsymbolsin string order ("1","10","2"). Written directly, a stdHashMapcomes out in an order that changes with every process. Clients read these tables in arrival order: rewrite-python keeps the first class literal per simple class name and streams a library's classes in the order it found them.These tables, and the one-shot mode's
files, are nowBTreeMaps, in ascending id order. The README states that order. A response is byte-identical across processes again, and stayed so over the five runs of each request above.responses_are_byte_identical_across_processessends the samegetTypesandgetLibraryApirequests to two processes and compares the raw response lines. With the tables back onHashMapit fails.