You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working to improve the performance of the deserializer. (See swc-project/swc#3160)
I found that serde::__private::de::Content is created quite frequently from __deserializer and __deserializer is serde::__private::de::ContentDeserailizer in many cases.
Try: specialization
So I copied code from serde, and specialized implementation of deserialize for Content.
impl<'de>Deserialize<'de>forContent<'de>{fndeserialize<D>(deserializer:D) -> Result<Self,D::Error>whereD:Deserializer<'de>,{
<ContentasDeserImpl<'de,D>>::deserialize_spec(deserializer)}}traitDeserImpl<'de,D>:SizedwhereD:Deserializer<'de>,{fndeserialize_spec(deserializer:D) -> Result<Self,D::Error>;}impl<'de,D>DeserImpl<'de,D>forContent<'de>whereD:Deserializer<'de>,{defaultfndeserialize_spec(deserializer:D) -> Result<Self,D::Error>{// Untagged and internally tagged enums are only supported in// self-describing formats.let visitor = ContentVisitor{value:PhantomData};
deserializer.deserialize_any(visitor)}}impl<'de,E>DeserImpl<'de,ContentDeserializer<'de,E>>forContent<'de>whereContentDeserializer<'de,E>:Deserializer<'de,Error = E>,{fndeserialize_spec(deserializer:ContentDeserializer<'de,E>) -> Result<Self,E>{Ok(deserializer.content)}}
Previous
test json_deserialize ... bench: 1,226,131 ns/iter (+/- 58,655)
After
test json_deserialize ... bench: 621,480 ns/iter (+/- 69,766)
I spotted few more creation of Content from serde::__private::de::ContentDeserailizer due to #[flatten] and going to implement custom #[derive(Deserialize)] which uses my fork of ContentDeserailizer.
But this is useful for many users ofserde, so I'm filing an issue.
specialization is not suitable for this because of the unsound interaction with lifetimes, and I would guess min_specialization is not expressive enough to implement this.
The same behavior can be achieved without specialization though. #2148
Context
I'm working to improve the performance of the deserializer. (See swc-project/swc#3160)
I found that
serde::__private::de::Content
is created quite frequently from__deserializer
and__deserializer
isserde::__private::de::ContentDeserailizer
in many cases.Try: specialization
So I copied code from serde, and specialized implementation of
deserialize
forContent
.Previous
After
I spotted few more creation of
Content
fromserde::__private::de::ContentDeserailizer
due to#[flatten]
and going to implement custom#[derive(Deserialize)]
which uses my fork ofContentDeserailizer
.But this is useful for many users of
serde
, so I'm filing an issue.Using fork
To quickly apply specialization for
ContentDeserailizer
of#[flatten]
, I created a fork (https://github.com/kdy1/serde/tree/content-specialization). Using it, I could get the result before creating a custom dervie macro.The text was updated successfully, but these errors were encountered: