@@ -477,8 +477,13 @@ impl TriplesBitmap {
477477 Self { order, bitmap_y : InMemoryBitmap :: new ( bitmap_y) , adjlist_z, op_index, wavelet_y }
478478 }
479479
480- /// Creates a new TriplesBitmap from a list of sorted RDF triples
481- pub fn from_triples ( triples : & [ TripleId ] ) -> Self {
480+ /// Creates a new TriplesBitmap from a list of sorted RDF triples.
481+ ///
482+ /// Takes the triples by value so the encoded-triple buffer (24 B ×
483+ /// num_triples) can be freed as soon as the y/z arrays and bitmaps are
484+ /// built, instead of staying resident through the memory-heavy op-index
485+ /// construction in [`TriplesBitmap::new`].
486+ pub fn from_triples ( triples : Vec < TripleId > ) -> Self {
482487 let mut y_bitmap = BitVectorMut :: new ( ) ;
483488 let mut z_bitmap = BitVectorMut :: new ( ) ;
484489 let mut array_y = Vec :: new ( ) ;
@@ -515,6 +520,10 @@ impl TriplesBitmap {
515520 last_y = y;
516521 last_z = z;
517522 }
523+ // The encoded triples have been fully read into the y/z arrays and
524+ // bitmaps; free them (~24 B × num_triples) before the op-index build
525+ // peak in TriplesBitmap::new rather than holding them until return.
526+ drop ( triples) ;
518527 y_bitmap. push ( true ) ;
519528 let n = y_bitmap. len ( ) ;
520529 y_bitmap. extend_with_zeros ( n. div_ceil ( 64 ) * 64 - n) ;
@@ -523,6 +532,10 @@ impl TriplesBitmap {
523532 let bitmap_z = Bitmap :: from ( z_bitmap) ;
524533 let sequence_y = Sequence :: new ( & array_y) ;
525534 let sequence_z = Sequence :: new ( & array_z) ;
535+ // The plain usize arrays are now redundant with the bit-packed
536+ // sequences; free them (~8 B × len each) before the op-index build.
537+ drop ( array_y) ;
538+ drop ( array_z) ;
526539 let adjlist_z = AdjList :: new ( sequence_z, bitmap_z) ;
527540 TriplesBitmap :: new ( Order :: SPO , & sequence_y, bitmap_y, adjlist_z)
528541 }
0 commit comments