CargoSense / vex

Data Validation for Elixir
MIT License
595 stars 60 forks source link

Vex custom validators are slow #62

Closed vasspilka closed 1 year ago

vasspilka commented 5 years ago

When using Vex custom validators the validation process seems to be taking a lot of time

jfornoff commented 5 years ago

This might be an issue that we have seen as well. Do you have a lot of custom validators? You could also try profiling with fprof to see where it is spending time exactly.

vasspilka commented 5 years ago

Yes, it seems to be related with custom validators. I will look into fprof and providing more details when I have the time for it. But it seems even simple custom validators take a lot time

jfornoff commented 5 years ago

OK I can give you a few pointers then. What happened to us is (AFAIR) that we spent a bunch of time looking up the Validator modules each time a validation was performed. I don't remember exactly how it is done by default, but it wasn't fast. Our workaround was to put our custom validators as well as the standard validators that we use into a explicit list in the config like so:

config :vex,
  sources: [
    [
      uuid: Common.Validation.Vex.UUID,
      exclusion: Vex.Validators.Exclusion,
      # And so on
    ]
  ]

Hope that helps, that's what I can retrieve from memory. If you need additional help, you can LMK and I can dig back into the source code when I find the time!

jfornoff commented 5 years ago

In terms of methodology, I recommend having a benchmark script with Benchee and then invoking mix profile.fprof --callers --details bench.exs. It is quite verbose but it allows you to pinpoint very well where time is spent.

vasspilka commented 5 years ago

@jfornoff Thank you for the tips, we will do the validation without vex for now, but will look into this in the future

jfornoff commented 5 years ago

Good luck! I hope to be able to remedy this issue at some point in the future, an approach similar to what Plug does would make sure the validators don't even have to be looked up in the first place, but it's not high on my priority list right now unfortunately