0
votes

I'm using class-validator in my newly created AWS lambda. When using the property decorators provided by class-validator, like @IsString(), the lambda gets painfully slow when invoking locally (~150ms without decorators, ~4000ms with decorators).

I'm not even validating the incoming object, just the fact the decorators are present slow down the lambda (as you may see, :

lambda handler (handler.ts)

export const serviceRequestsHandler = async (event: APIGatewayProxyEvent & { body: RequestBody, queryStringParameters: RequestQueryString }): Promise<APIGatewayProxyResult> => {

  const parsedBody: RequestBody                   = new RequestBody(event.body);

  return new ResponseFactory().statusCode(204)
                              .body(null)
                              .factory();
};

RequestUser.ts

import { IsString } from 'class-validator';

export class RequestBody {

  @IsString()
  contact_person: string;

  @IsString()
  machine_identifier_customer: string;

  @IsString()
  message: string;

  constructor(request_body: RequestBody) {
    this.contact_person              = request_body.contact_person;
    this.machine_identifier_customer = request_body.machine_identifier_customer;
    this.message                     = request_body.message;
  }

}

As you can see, no hard work is done here what could cause an increase of ~4000ms, and no validation of the event.body object itself. If I get rid of the decorators, runtime decreases, as mentioned, to about ~150ms.

Anyone has a guess what could cause this?

Thanks!