DEV Community

Discussion on: Are BigInt Math Calculations More Expensive Than Using Numbers in JavaScript?

halented profile image
Hal Dunn Author

Interesting thoughts, thanks for the comment! As for your first question, whether keeping a linked-list library would be better than using V8 — it would be tough to gauge, as I think it depends on how frequently your library is used, how efficiently the methods run, and the intent behind creating the library in the first place: will it be purely internal? Will the company publish it as open source down the line? There are a lot of unknowns there. Instinctively, I would lean towards using V8 because they have had years to test and improve on software which solves specifically this type of problem.
With that said, I think the cost of conversion from lists to numbers (to possibly BigInts) and back to lists is pretty high, especially if we assume this process would happen thousands of times a day.
If tasked with persisting the numbers to the disk, I would store them as Strings, one and all, the way JSON does — that way we don’t need to deal with whether or not they are BigInts unless they are being used in the functional side of the app.
Overall, your questions really bring to light the fact that the problem as posed to me didn’t contain enough detail to tell whether using BigInts could be considered “worth it” or not. I think it would be a situational answer, which would need hard data like type & frequency of requests to really make a call.