use codegen to generate doument validation function. this is significantly faster then old code.