TryValidateModel is slow with large arrays #5887
Comments
This bug was actually fixed recently and is available in nightly builds. ce53675 Meanwhile you could update the MVC options to exclude byte array from validation (this effects the entire app but I can't see why we do not do this by default. @dougbu ?) options.ModelMetadataDetailsProviders.Add(new SuppressChildValidationMetadataProvider(typeof(byte[]))); |
Correcting my previous comment :-)...We don't know if this a bug yet but there is a new way (through ValidateNever) through which you can selectively disable validation. |
Yes, I've read about ValidateNever and it looks cool. But I think of it as a workaround in this situation. I think it is dangerous to globally exclude byte arrays from validation... By the way, validation is also very slow for lists with a few thousand entries. If I change my model to public class MyModel
{
[Required]
public string Id { get; set; }
[Required]
public List<byte> Data { get; set; }
[Required]
public Dictionary<string, string> Metadata { get; set; }
} the problem still exists. |
@kichalla - using |
Isn't it something like:
in |
@Yves57 it would be similar to what you've got. Should also confirm no validators are configured for Put another way, your suggestion is a good way to avoid recursion through the metadata to find validators. Still need to look for those validators. |
Looking at this issue again, this is definitely something we should profile and try to improve. Secondly, we need to hold on to this piece of design feedback: it should be possible for model binding to determine that a graph is a 'no-op'. Today we can't/don't due to that due to the flexibility to the validator providers have in MVC, and we're contributing a lot to global warming. We should make sure that any new validation system can determine when not to explore an object graph with greater vigour. |
Moving this to 3.0 |
Back to 2.2.0-preview3 |
… validation metadata is discovered Fixes #5887
The code
is very slow when i pass a model with huge arrays. My model looks roughly like this:
If
Data
is only a few KB, everything is fine. However, ifData
is filled with ~5MB, the validation takes nearly 2 seconds on my machine. I'm using .NET Core 1.1.Of course, I could disable validation for
MyModel
and validate the properties myself... But I still think this is a bug, since I could not find any information on this topic (e.g. not to use validation on large arrays).Note: Removing the
[Required]
fromData
doesn't make any difference.The text was updated successfully, but these errors were encountered: