Skip to content

very slow schema creation for a large array #1409

@piotr-s-brainhub

Description

@piotr-s-brainhub

Context

  • node version: 8.9.4
  • joi version: 13.1.1
  • environment (node, browser): NodeJS
  • used with (hapi, standalone, ...): standalone
  • any other relevant information: -

What are you trying to achieve or the steps to reproduce ?

const Joi = require('joi');

const list = [];
for (let i = 10000; i < 50000; i++) {
  list.push(i.toString());
}

const filteredList = list.filter(x => !['12345', '23456', '34567', '456789'].includes(x));

console.time();
Joi.object().keys({
  foo: Joi.string().valid(filteredList),
});
console.timeEnd();

Which result you had ?

It works very slow (25385.524ms - almost half a minute).

What did you expect ?

It should work much faster (shorter than 1 second).

Metadata

Metadata

Assignees

Labels

featureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions