Skip to content

Commit

Permalink
[PERF] helpers: reduce toZone memory allocation
Browse files Browse the repository at this point in the history
On RNG' spreadsheet, this changes reduces memory allocation of
`toZoneWithoutBoundaryChanges` by ~40Mb when loading the spreadsheet.
It was ~93Mb before.

Two changes:
- avoid compiling a regexp every time
- avoid useless array allocation when it's a single cell reference

Each change accounts for ~20Mb saved.

closes #4174

Task: 3915798
X-original-commit: cefa559
Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
  • Loading branch information
LucasLefevre committed May 7, 2024
1 parent 670d87d commit 6ad0a05
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/helpers/zones.ts
Expand Up @@ -25,21 +25,22 @@ export function toZoneWithoutBoundaryChanges(xc: string): UnboundedZone {
xc = xc.split("!").at(-1)!;
}
if (xc.includes("$")) {
xc = xc.replace(/\$/g, "");
xc = xc.replaceAll("$", "");
}
let ranges: string[];
let firstRangePart: string = "";
let secondRangePart: string | undefined;
if (xc.includes(":")) {
ranges = xc.split(":").map((x) => x.trim());
[firstRangePart, secondRangePart] = xc.split(":");
firstRangePart = firstRangePart.trim();
secondRangePart = secondRangePart.trim();
} else {
ranges = [xc.trim()];
firstRangePart = xc.trim();
}

let top: number, bottom: number, left: number, right: number;
let fullCol = false;
let fullRow = false;
let hasHeader = false;
const firstRangePart = ranges[0];
const secondRangePart = ranges[1] && ranges[1];

if (isColReference(firstRangePart)) {
left = right = lettersToNumber(firstRangePart);
Expand All @@ -55,7 +56,7 @@ export function toZoneWithoutBoundaryChanges(xc: string): UnboundedZone {
top = bottom = c.row;
hasHeader = true;
}
if (ranges.length === 2) {
if (secondRangePart) {
if (isColReference(secondRangePart)) {
right = lettersToNumber(secondRangePart);
fullCol = true;
Expand Down

0 comments on commit 6ad0a05

Please sign in to comment.