Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the perf issue in building nodes from splits. (run-llama#10766)
* Fix the perf issue in building nodes from splits. Create the `relationships` object only once. Otherwise, it recomputes the whole text's hash for every node. It is very inefficient for long text. An alternative approach would be to cache the hash property. However, it wasn't so straightforward as `Document` isn't a cacheable type. I also do not know Python very well, maybe it would be enough to store a simple null and if it isn't null, then don't recompute? However, the most important reason is I'm not sure about the side effects and the existing assumption that the node is mutable and the hash always reflects the state during the call (unless we modify the object in multiple threads). This change doesn't break any assumptions. If the document was modified while we were creating nodes extracted from it, something would be very wrong. Benchmarks taken on a document attached to the bug: Before: Execution time for build_nodes_from_splits: 53.69 seconds After: Execution time for build_nodes_from_splits: 0.18 seconds * Fix the formatting
- Loading branch information