bravius opened a new issue, #236: URL: https://github.com/apache/age/issues/236
Ran into a problematic limitation of JavaScript when using the bundled pg-age Node.js driver, which appears to convert the 64-bit graphid to JavaScript's floating Number type. According to the Mozilla JavaScript reference: `The Number.MAX_SAFE_INTEGER constant represents the maximum safe integer in JavaScript (2^53 - 1).` https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER From the source (graphid.h/graphid.c) it appears graphid is composed of a 48 bit entry id and a 16 bit label id: ``` ENTRY_ID_BITS = (32 + 16) ENTRY_ID_MASK = 0x0000ffffffffffff graphid = (((uint64)label_id) << ENTRY_ID_BITS) | (((uint64)entry_id) & ENTRY_ID_MASK) ``` Given that entry ids are scaled to 48 bits, and JavaScript integer precision is limited to 2^53-1, this essentially leaves just 5 bits for label ids, or a maximum of 32 labels. Any graphid exceeding JavaScript's maximum guaranteed integer precision would have to be considered unreliable. Upon testing this, in fact, graphids already start exceeding Number.MAX_SAFE_INTEGER after creating just 30 labels. Some thoughts on solving this for graphs with more than 29 labels: 1) Change ENTRY_ID_BITS and ENTRY_ID_MASK to 40 bits and rebuild. Would still leave room for over a trillion entries per label. 2) Have the pg-age Node.js driver parse graphids as strings, or possibly as BigInt, though using BigInt would not be serializable using the standard JSON parse / stringify. Any thoughts on the best way to deal with this? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
