-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: use ArcStr for storing strings in Schema #1247
base: master
Are you sure you want to change the base?
Conversation
8b02019
to
7e3e6b4
Compare
juniper/src/schema/model.rs
Outdated
match *t { | ||
Type::NonNullNamed(ref n) => TypeType::NonNull(Box::new( | ||
self.type_by_name(n).expect("Type not found in schema"), | ||
pub fn make_type(&self, t: DynType) -> TypeType<S> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is public, but DynType
/AsDynType
are not exported, so in the generated rustdocs this method is visible, but I'm unsure whether it's actually usable from outside juniper since you would have a hard time instantiating a DynType
value?
Should functions that have private(ish) types in their signature be pub(crate)
instead?
Sweet, this looks great! I don't have time to look at this right now but perhaps @tyranron has opinions. |
@LegNeato this is definitely on my agenda in near future. However, the diif is huge enough, which will take some time. |
BREAKING CHANGE: Schema types are not lifetime-generic anymore
@audunhalland I'm going to review this in next few days and release in 0.17.0. |
@tyranron cool, I'm not 100% happy with all parts of this PR, there are surely things that can be iterated on later. Especially I see edit: also note for the review: I'm not sure I understand the
|
That should be fine, yes.
|
@tyranron an idea: Could we somehow make (Ideally edit: |
@tyranron I see there are some compile errors on the bikeshedded changes now. Should I help out with trying to resolve those? |
Fixes #819
This is an experiment that uses arcstr::ArcStr for storing strings within the GraphQL schema. String literals that are constant/come from macros no longer allocate memory.
ArcStr
appears to fit perfectly for juniper in my opinion. It delivers extremely cheap literal strings, which is the most common usecase, while also supporting dynamic schemas based on extensive use of customTypeInfo
(which is how we're using juniper at work), potentially without extra memory allocation. There's of course the "cost" that users have to see ArcStr in the dynamic schema building APIs, but I think that with these new APIs exposed it should be much clearer when juniper needs to allocate string memory and where it's "free" (usingliteral!
). In short, this choice is now put in the hands of the user.BREAKING CHANGE:
GraphQLValue::type_name
andGraphQLType::name
both returnOption<ArcStr>
instead ofOption<&str>
.Benchmark results
master
arcstr
All of the improvements should be related to schema creation, not the query executor.