Skip to content

TCString.encode is very slow #444

Open
@morinel

Description

@morinel

Version
1.5.11

Module (core, cmpapi, cli, stub, or testing)
core

Describe with reproduction steps – What is the expected behavior?
TCString.encode(model) is very slow because most of its runtime is spent in stringifying and parsing the GVL JSON as part of a clone() operation in the TCModel. The TCModel has gvl and publisherRestrictions members where the publisherRestrictions itself has a gvl member too. This results in the GVL being cloned twice as can be seen in this Performance overview:

Screenshot 2024-04-18 at 23 17 08

As Google is increasingly focusing on the INP CoreWebVital metric it is almost impossible to score favorably because of the bad performance of the encode operation. Google recommends to make sure the JavaScript main thread is not kept occupied more than 50 ms for each task for improved user experience. The task in the screenshot took 120 ms of which approx. 75 ms were spent in two getJson() calls.

Is there any reason why the GVL is cloned twice and why it is implemented like:

(https://github.com/InteractiveAdvertisingBureau/iabtcf-es/blob/master/modules/core/src/GVL.ts#L403-L417)

return JSON.parse(JSON.stringify({
    gvlSpecificationVersion: this.gvlSpecificationVersion,
    vendorListVersion: this.vendorListVersion,
    tcfPolicyVersion: this.tcfPolicyVersion,
    lastUpdated: this.lastUpdated,
    purposes: this.purposes,
    specialPurposes: this.specialPurposes,
    features: this.features,
    specialFeatures: this.specialFeatures,
    stacks: this.stacks,
    dataCategories: this.dataCategories,
    vendors: this.fullVendorList,
}));

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions