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

Make tcencode more performant by avoiding json roundtrip conversion #446

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions modules/core/src/GVL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,21 +401,33 @@ export class GVL extends Cloneable<GVL> implements VendorList {
* functionality and methods of this class.
*/
public getJson(): VendorList {

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,
}));

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
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a deep clone of VendorList, right? We will return references to objects like vendors and anyone outside of the library could update it, maybe it's not good.

The JSON.parse(JSON.stringify()) is ugly and very slow particular for the very big object like GVL. Maybe we can develop an alternative solution creating custom deep clone method in this case as we know the GVL structure?

}

/**
Expand Down