How exactly does AlwaysSparse work? #761
Replies: 2 comments 5 replies
-
|
Beta Was this translation helpful? Give feedback.
-
Figured it out as per the help above. I used the Here's how I acheived it: const sheet = getSheetId()
// https://github.com/handsontable/hyperformula/discussions/761
const addressMapping = hyperformula.dependencyGraph.addressMapping.mapping;
const serializedValues = [];
const currentSheetMapping = addressMapping.get(sheet);
currentSheetMapping.mapping.forEach((col, colKey) => {
col.forEach((_, rowKey) => {
const cellAddress = { sheet, col: colKey, row: rowKey };
const serializedValue = hyperformula.getCellSerialized(cellAddress);
if (!isNil(serializedValue) && serializedValue !== "") {
if (!serializedValues[rowKey]) {
serializedValues[rowKey] = [];
}
serializedValues[rowKey][colKey] = serializedValue;
}
});
}); This gives me an efficient sparse array like so:
Instead of an array filled with null/undefined values and is much faster to loop through. I really think this would be a super useful function, i.e something like There is also an issue with this in that Which means I have to loop through my array and use |
Beta Was this translation helpful? Give feedback.
-
Is their an example on what these configs actually do?
Example with
AlwaysSparse
on the #develop branch:output:
This is the same output as
AlwaysDense
:performance.md says:
I would have expected that
AlwaysSparse
uses sparse arrays here instead of nulls and empty arrays to save on memory output instead of filling it with useless nulls. Is this not the case?I'm just trying to make my sheet performant as possible due to the possibility that a user will had a cell in row 10000, column 10000 for example which I presumed the sparse strategy would help with.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions