Skip to content

Caching of compiled regexes doesn't work in openapi3 schema validation #1075

@philpearl

Description

@philpearl

Here in the openapi 3 code it tries to cache a compiled regex in a sync map with a CompareAndSwap call, attempting to insert the new compiled regex in the map if the previous entry was nil.

Unfortunately this will never work as this call will only swap with an existing entry. If there is no existing entry for the key CompareAndSwap will not make a swap.

It is simple to fix the problem by replacing the CompareAndSwap call with a Store call. In my testing this halved the time take for validation of our schema, and reduced the allocations from 1133 per validation to 361.

I'm happy to provide a PR for this problem if desired.

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