Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Serde is slow #222

Copy link
Copy link
Closed
Closed
Copy link
@compiler-errors

Description

@compiler-errors
Issue body actions

This code seems to have a linear relationship in its slowness based on the length of the macro input:

#![allow(warnings)]

use serde::de::Error as DeError;
use serde::{de::*, ser::*};
use std::fmt;
use std::marker::PhantomData;

macro_rules! tri {
    ($expr:expr) => {
        match $expr {
            Ok(val) => val,
            Err(err) => return Err(err),
        }
    };
}

macro_rules! tuple_impls {
    ($(($($n:tt $name:ident)+))+) => {$(
        const _: () = { struct TupleVisitor<$($name,)+> {
            marker: PhantomData<($($name,)+)>,
        }

            fn visit_seq<'de, $($name: Deserialize<'de>,)+ A>(this: TupleVisitor<$($name,)+>, mut seq: A) -> Result<($($name,)+), A::Error>
            where
                A: SeqAccess<'de>,
            {
                $(
                    let $name = match tri!(seq.next_element()) {
                        Some(value) => value,
                        None => todo!(),
                    };
                )+

                Ok(($($name,)+))
            }
    };)*}
}

tuple_impls! {
    (0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8 9 T9 10 T10 11 T11 12 T12 13 T13 14 T14 15 T15 16 T16 17 T17)
}

What's weird is that, AFAICT, there's no aliases going on. Just a lot of ?t: Trait bounds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.