Skip to content

Commit

Permalink
perf(): use JSON.parse() when metadata is > 10KB
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Jun 26, 2019
1 parent 2054cc7 commit ab0e9d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/compiler/app-core/format-component-runtime-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ export function formatComponentRuntimeMeta(compilerMeta: d.ComponentCompilerMeta


export function stringifyRuntimeData(data: any) {
// stringify the data, then remove property double-quotes so they can be property renamed
return JSON.stringify(data);
const json = JSON.stringify(data);
if (json.length > 10000) {
// JSON metadata is big, JSON.parse() is faster
// https://twitter.com/mathias/status/1143551692732030979
return `JSON.parse(${JSON.stringify(json)})`;

This comment has been minimized.

Copy link
@mathiasbynens

mathiasbynens Jun 26, 2019

Is this injected into an inline <script>? If so, you need additional escaping — otherwise this is an XSS vulnerability. See https://twitter.com/mathias/status/1143784574159347712.

}
return json;
}


Expand Down
1 change: 1 addition & 0 deletions src/compiler/component-lazy/generate-lazy-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export async function generateLazyModules(config: d.Config, compilerCtx: d.Compi
]);

const lazyRuntimeData = formatLazyBundlesRuntimeMeta(bundleModules);
config.logger.debug(`Upfront metadata is ${lazyRuntimeData.length} bytes`);
const entryResults = rollupResults.filter(rollupResult => !rollupResult.isComponent && rollupResult.isEntry);
await Promise.all(
entryResults.map(rollupResult => {
Expand Down

0 comments on commit ab0e9d6

Please sign in to comment.