Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCString.encode is very slow #444

Open
morinel opened this issue Apr 18, 2024 · 2 comments
Open

TCString.encode is very slow #444

morinel opened this issue Apr 18, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@morinel
Copy link

morinel commented Apr 18, 2024

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,
}));
@morinel morinel added the bug Something isn't working label Apr 18, 2024
@lamrowena lamrowena assigned lamrowena and sevriugin and unassigned lamrowena Apr 25, 2024
@HeinzBaumann
Copy link
Collaborator

Regarding "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)". I think the double clone is a side effect of us calling two static JSON functions to get a JSON object. I don't know why this was done this way. I loop in IAB TechLab folks to help review and debug this. In the meantime if anyone has any idea how this can be approved, feel free to suggest it. this library is open source, meaning we are happy for your contribution.

@patmmccann
Copy link

patmmccann commented Apr 25, 2024

it seems you shouldnt need to do all the json calls. To get the object stripped to just what you need, which seems to be the goal of the function, you can do something like this. I put in a pr to try and avoid them

`public getJson(): VendorList {
const {
gvlSpecificationVersion,
vendorListVersion,
tcfPolicyVersion,
lastUpdated,
purposes,
specialPurposes,
features,
specialFeatures,
stacks,
dataCategories,
fullVendorList
} = this;

return {
    gvlSpecificationVersion,
    vendorListVersion,
    tcfPolicyVersion,
    lastUpdated,
    purposes,
    specialPurposes,
    features,
    specialFeatures,
    stacks,
    dataCategories,
    vendors: fullVendorList
};

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants