mswjs / data

Data modeling and relation library for testing JavaScript applications.

Home Page:https://npm.im/@mswjs/data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Saving (and loading) an initialized factory

tinleym opened this issue · comments

Is there a good way to save an initialized factory to file to load later? I'd like to be able to start up a bigger factory faster.

Hey, @tinleym.

There's no designated API for that. We are implementing what effectively is serialization/deserialization of entities in #87 but I can't give any promises that are going to be a public API you can utilize on your own.

Are you concerned with the runtime or compile-time performance? If it's the former, consider using memorization and other similar tools to reduce the cost of generating a large number of entities. I don't think you can achieve much compile-time performance as the main load happens internally in the library (iteration over model properties, seeding their values, defining the relations).

The most important question I'd ask is: what kind of performance issues you are experiencing? Do you have some metrics to share?

We have some performance tests in the repo and the current benchmark is 1000 entities in ~80ms. It's worth mentioning that the metrics are synthetic and use a rather plain model definition (no relations, for example). That should still be a fairly good default. I'd like to learn more from you about the performance issues you're experiencing.