Skip to content

Deserialization performance #49

@m-sasha

Description

@m-sasha

Deserialization performance can be drastically improved by caching the list of builder methods. Here's a typical flame chart for reading mavlink messages in a loop:
mavlink-reading

You can see that sorting the builder methods takes almost half the deserialization time. This can easily be solved with:

    private static final Map<Class<?>, List<Method>> builderMethodsCache = Collections.synchronizedMap(new HashMap<>());


    private static List<Method> getBuilderMethods(Class<?> builderClass){
        return builderMethodsCache.computeIfAbsent(builderClass, (c) -> Arrays.stream(c.getMethods())
                .filter(m -> m.isAnnotationPresent(MavlinkFieldInfo.class))
                .sorted((a, b) -> {
                    MavlinkFieldInfo fa = a.getAnnotation(MavlinkFieldInfo.class);
                    MavlinkFieldInfo fb = b.getAnnotation(MavlinkFieldInfo.class);
                    return wireComparator.compare(fa, fb);
                }).collect(Collectors.toList()));
    }

in ReflectionPayloadDeserializer.

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