perf(ivy): avoid extra parameter in query instructions (#31667)

Currently we always generate the `read` parameter for the view and content query instructions, however since most of the time the `read` parameter won't be set, we'll end up generating `null` which adds 5 bytes for each query when minified. These changes make it so that the `read` parameter only gets generated if it has a value.

PR Close #31667
This commit is contained in:
crisbeto
2019-07-20 12:32:29 +02:00
committed by Miško Hevery
parent 716af1059c
commit 3d7303efc0
8 changed files with 77 additions and 77 deletions

View File

@ -449,11 +449,10 @@ function selectorsFromGlobalMetadata(
}
function prepareQueryParams(query: R3QueryMetadata, constantPool: ConstantPool): o.Expression[] {
const parameters = [
getQueryPredicate(query, constantPool),
o.literal(query.descendants),
query.read || o.literal(null),
];
const parameters = [getQueryPredicate(query, constantPool), o.literal(query.descendants)];
if (query.read) {
parameters.push(query.read);
}
return parameters;
}
@ -480,12 +479,13 @@ function createContentQueriesFunction(
const tempAllocator = temporaryAllocator(updateStatements, TEMPORARY_NAME);
for (const query of queries) {
// creation, e.g. r3.contentQuery(dirIndex, somePredicate, true, null);
const args = [o.variable('dirIndex'), ...prepareQueryParams(query, constantPool) as any];
const queryInstruction = query.static ? R3.staticContentQuery : R3.contentQuery;
createStatements.push(o.importExpr(queryInstruction).callFn(args).toStmt());
// creation, e.g. r3.contentQuery(dirIndex, somePredicate, true, null);
createStatements.push(
o.importExpr(queryInstruction)
.callFn([o.variable('dirIndex'), ...prepareQueryParams(query, constantPool) as any])
.toStmt());
// update, e.g. (r3.queryRefresh(tmp = r3.loadContentQuery()) && (ctx.someDir = tmp));
const temporary = tempAllocator();