Skip to content

Compiled serializer is huged because of serializerState #45

Closed
@remidewitte

Description

@remidewitte

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the regression has not already been reported

Last working version

4.20

Stopped working in version

4.3.0

Node.js version

20.x

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

💥 Regression Report

Every compiled schema contains a stringified version of the schema. Issue is when the schema is huged.
Today it almost kills the advantage of compilation.

It comes from the bump to v5.7.0 of fast-json-stringify.
And to be specific if comes from : fastify/fast-json-stringify#617.

It seems that this getState() of the serializer is never used.

Steps to Reproduce

async function main() {
  const app = fastify({
    exposeHeadRoutes: false,
    jsonShorthand: false,
    schemaController: {
      compilersFactory: {
        buildSerializer: writeSerializerFactory,
      },
    },
    logger: {
      level: 'debug'
    }
  });

  addAllSchemas(app);

  await app.register(async api => {
    api.register(... all handlers ...)
  });

  await app.ready().then(() => {
    app.log.info('Ready, all serializer compiled');
    app.close();
  });
}


export const writeSerializerFactory = StandaloneSerializer({
  readMode: false,
  storeFunction(routeOpts, schemaSerializationCode) {
    if (routeOpts.method === 'HEAD') {
      return;
    }
    writeFileSync(generateSerializerFilePath(routeOps), schemaSerializationCode);
  },
});

Expected Behavior

Why have this serializerState ? Is does not seem to be used at all ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions