Skip to content

Investigate switching to binary search for struct field lookup #4

Closed

Description

@jcrist

Currently we use an (augmented) linear search when matching struct fields to struct keys. This is performant if the number of fields is small (for some value of small) or the fields are serialized in roughly the same order as they're defined. If mgspec is used with the same schema for both serializer and deserializer, this is as efficient as it can get (matching is a single memcmp call).

For large numbers of fields or fields in different serialization orders, linear search likely won't perform as well. We should investigate modifying the search algorithm to maybe fallback to binary search if the first attempt fails (so we're still performant in the common case, but not terrible in the pathological case).

Activity

  1. jcrist commented on Jul 26, 2022

    @jcrist
    MemberAuthor

    After some benchmarking, what we have here already seems to be the most performant solution for common sized structs. Branch prediction and cache effects trump big-O notation. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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