-
Notifications
You must be signed in to change notification settings - Fork 95
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
perf: improve performance of purpose restriction encoder [encode] #424
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,19 +14,28 @@ export class PurposeRestrictionVectorEncoder { | |
// if the vector is empty we'll just return a string with just the numRestricitons being 0 | ||
if (!prVector.isEmpty()) { | ||
|
||
const nextGvlVendor = (vendorId, lastVendorId): number => { | ||
const gvlVendorIds = Array.from(prVector.gvl.vendorIds); | ||
|
||
for (let nextId = vendorId + 1; nextId <= lastVendorId; nextId++) { | ||
const nextGvlVendor = (vendorId, lastVendorId) => { | ||
|
||
if (prVector.gvl.vendorIds.has(nextId)) { | ||
const firstIndex = gvlVendorIds.indexOf(vendorId); | ||
const lastIndex = gvlVendorIds.indexOf(lastVendorId); | ||
|
||
return nextId; | ||
if (lastIndex - firstIndex > 0) { | ||
|
||
} | ||
const nextIndex = gvlVendorIds.indexOf(vendorId + 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. vendorId + 1 could be out of range if vendorId is the last vendor in the GVL, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the vendorId is the last vendor in the GVL this block won't be executed, in fact the vendorId is the latest this function will return itself as "special case". See return statement at line 35 |
||
|
||
return { | ||
nextVendorId: gvlVendorIds[nextIndex], | ||
index: gvlVendorIds[firstIndex + 1], | ||
}; | ||
|
||
} | ||
|
||
return vendorId; | ||
return { | ||
nextVendorId: vendorId, | ||
index: vendorId, | ||
}; | ||
|
||
}; | ||
|
||
|
@@ -60,10 +69,28 @@ export class PurposeRestrictionVectorEncoder { | |
|
||
} | ||
|
||
let isRangeEncodeRequired = i === len - 1; | ||
|
||
if (!isRangeEncodeRequired) { | ||
|
||
const {nextVendorId, index} = nextGvlVendor(vendorId, vendors[len - 1]); | ||
|
||
if (vendors[i + 1] > nextVendorId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. vendors[i+1] is always defined ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, in fact if it is not defined the relevant block of code will not be executed. See the condition at line 74 and the condition at line 61 |
||
|
||
isRangeEncodeRequired = true; | ||
|
||
} else if (index > i && index < len) { | ||
|
||
i = index; | ||
|
||
} | ||
|
||
} | ||
|
||
/** | ||
* either end of the loop or there are GVL vendor IDs before the next one | ||
*/ | ||
if (i === len - 1 || vendors[i + 1] > nextGvlVendor(vendorId, vendors[len - 1])) { | ||
if (isRangeEncodeRequired) { | ||
|
||
/** | ||
* it's a range entry if we've got something other than the start | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this one be true if first index is equal -1 -> not found?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that condition is required only to check if we are at the "end" of the used GVL vendor list in fact in line 26 you see we are taking the nextIndex the one that is specified in the GVL vendor list.
This makes possible to skip every extra loop in the purpose restriction encode process.