Skip to content

Extremely slow validation on repeated field with items validationΒ #304

@andrey-filenko-quarks-tech

Description

Description

When I am using validation rules on items for repeated fields with env variable PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=upb, validation is extremely slow

Steps to Reproduce

Using the following message:

message RepeatedItems {
  repeated int64 items = 1 [
    (buf.validate.field).repeated = {
      items: {
        int64: {gt: 0}
      }
    }
  ];
}

Run this code:

import protovalidate
import time
from gen.tests.example.v1 import validations_pb2

msg = validations_pb2.RepeatedItems(items=[i + 1 for i in range(2000)])

start = time.perf_counter()
protovalidate.validate(msg)
end = time.perf_counter()
print(f"Finished one in {end-start:.2f} seconds")

Is executing about:

PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=upb python main.py
Finished one in 2.08 seconds

and with PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python:

PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python python main.py
Finished one in 0.01 seconds

But I guess both are pretty slow for just a validation call.

I have tried pre-warming up and doing it in a loop, however, numbers are the same after first call.

Environment

  • Operating System: macOS Sequoia
  • Compiler/Toolchain: Apple clang version 17.0.0 (clang-1700.0.13.3)
  • Protobuf Compiler & Version: buf v1.54.0
  • Protovalidate Version: v0.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    WishlistThings we'd want in the future

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions