-
Notifications
You must be signed in to change notification settings - Fork 183
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
generating 100k rows in excel crashes the browser #18
Comments
At which point is it crashing? Which browser(s)? Could you provide a full working code example as an attachment that I could run? |
Hi ... here is a repository with the project. Im developing on chrome and the browser memory is inflated on line 55 --> export.js thanks :-) |
Thanks. The problem is that in line 55 you are setting the value for 2 million cells. Whenever you set the value for a cell, an object gets created for it that looks something like this: {
attributes: { r: "A1", s: "1", t: "s" },
children: [{
name: "v",
children: [5]
}]
} Dumping a heap snapshot, it looks like that object takes around 600 bytes. Multiply that by 2 million and you run into the V8 heap limit. While I'm sure it's possible to find ways to minimize the memory, it's not easy and is unlikely to happen. The good news is that the limit in Chrome/Node.js does seem to be right about 2 million cells. That seems to be a healthy amount for most use cases. |
I see ... |
Nope. The file has to be held in memory in the browser. Do you need more than 2 million cells? |
@dtjohnson @rivlinehud there's actually a lower limit to be aware of: V8 strings cannot be larger than 256 MB nodejs/node#3175 (comment) |
@dtjohnson, yepp ... i need the capability to export large stock files ... |
@reviewher, thanks for that. I wasn't aware of the string limit. That's not the issue in this particular problem, but I'm sure I'll run into it at some point. @rivlinehud, how many cells do you need? We should be able to get to 4 million cells without too much difficulty... |
@dtjohnson, 4 million cells would be amaizing !!! :-) |
OK. So this is going to be harder than I thought. With the current setup you are actually limited to about 650k cells if you want to output a file. While you can certainly get 2M cells in memory, the downstream steps to turn it into a file consume additional memory. I do think 3-4 million cells should be possible, but it will require a lot more effort. Here is the basic process the xlsx-populate uses:
So to summarize, I do think it's possible to get to 3-4 million cells, but there's a decent amount of work to get there. You might be better off looking at another library like Sheet JS for the time being. |
OK. So I just published v1.2.0, which is as far as I'm going to take this at this point. I shaved the memory of the data structure a bit and a rewrote the XML builder from scratch, which saved a huuuuge amount of memory. Right now you can get just over 2 million cells in Chrome. Now CPU is the big bottleneck. Also, performance in IE is terrible in general, and this doesn't fair well either. I'm hesitant to push performance too much more at this stage. I'd rather wait for more completeness of the API before. So hopefully this is good enough for you. |
thanks so much !! :-) i will do some tests soon and let you know my experience with the uppgrade |
I just published v1.6.0 that has much better performance. In tests in V8 I was able to generate 9.5 million cells. |
Amazing! I've tried a few libraries that would all run out of memory and crash the browser before finding this one. This was able to do approximately 3.75 million cells in a file I just generated. Great work! |
Is there a way to over come this memory crash issue. I am trying to load a 60 mb xlsx. |
Hi :-) I love this project !
Is it possible to stream the file, instead of inflating the browsers cash ?
I attached some code bellow
thanks a lot :-)
`function doExport(page, options) {
return generate(page, options)
.then(function (blob) {
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
//ie
window.navigator.msSaveOrOpenBlob(blob, page + ".xlsx");
} else {
//not ie
var url = window.URL.createObjectURL(blob);
var a = document.createElement("a");
document.body.appendChild(a);
a.href = url;
a.download = page + ".xlsx";
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
}
})
.catch(function (err) {
alert(err.message || err);
throw err;
});
}
function generate(page,options) {
options = options || {};
}
function getWorkbook(lang) {
lang = lang || "En";
return new Promise(function (resolve, reject) {
}`
The text was updated successfully, but these errors were encountered: