kacper-li-airspace-intelligence commented on code in PR #3224:
URL: https://github.com/apache/iceberg-rust/pull/3224#discussion_r4259670059


##########
crates/iceberg/src/spec/manifest_list/mod.rs:
##########
@@ -58,22 +57,39 @@ pub struct ManifestList {
 
 impl ManifestList {
     /// Parse manifest list from bytes.
+    /// Convert each Avro value immediately, retaining only the final typed 
entries.
+    /// A decoding or conversion error still discards the entire result.
     pub fn parse_with_version(bs: &[u8], version: FormatVersion) -> 
Result<ManifestList> {
         match version {
             FormatVersion::V1 => {
                 let reader = 
Reader::with_schema(&MANIFEST_LIST_AVRO_SCHEMA_V1, bs)?;
-                let values = 
Value::Array(reader.collect::<std::result::Result<Vec<Value>, _>>()?);
-                from_value::<_serde::ManifestListV1>(&values)?.try_into()
+                let entries = reader
+                    .map(|value| {
+                        let value = value?;
+                        
from_value::<_serde::ManifestFileV1>(&value)?.try_into()
+                    })
+                    .collect::<Result<Vec<_>>>()?;
+                Ok(ManifestList { entries })
             }
             FormatVersion::V2 => {
                 let reader = Reader::new(bs)?;
-                let values = 
Value::Array(reader.collect::<std::result::Result<Vec<Value>, _>>()?);
-                from_value::<_serde::ManifestListV2>(&values)?.try_into()
+                let entries = reader
+                    .map(|value| {
+                        let value = value?;
+                        
from_value::<_serde::ManifestFileV2>(&value)?.try_into()
+                    })
+                    .collect::<Result<Vec<_>>>()?;
+                Ok(ManifestList { entries })
             }
             FormatVersion::V3 => {
                 let reader = Reader::new(bs)?;
-                let values = 
Value::Array(reader.collect::<std::result::Result<Vec<Value>, _>>()?);
-                from_value::<_serde::ManifestListV3>(&values)?.try_into()
+                let entries = reader
+                    .map(|value| {
+                        let value = value?;
+                        
from_value::<_serde::ManifestFileV3>(&value)?.try_into()
+                    })
+                    .collect::<Result<Vec<_>>>()?;
+                Ok(ManifestList { entries })
             }
         }
     }

Review Comment:
   Done. I merged `main` and use your `into_deser_iter` version. Peak is now 
4,355,177 bytes, against 31,194,672 on `main`.



##########
crates/iceberg/tests/manifest_list_memory.rs:
##########
@@ -0,0 +1,200 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Manifest-list compatibility and peak live-allocation regression.
+
+use std::alloc::{GlobalAlloc, Layout, System};
+use std::sync::atomic::AtomicUsize;
+use std::sync::atomic::Ordering::Relaxed;
+use std::time::Instant;
+
+use apache_avro::types::Value;
+use apache_avro::{Codec, Reader, Writer};
+use iceberg::io::FileIO;
+use iceberg::spec::{
+    FieldSummary, FormatVersion, ManifestContentType, ManifestFile, 
ManifestList,
+    ManifestListWriter,
+};
+
+struct CountingAllocator;
+static LIVE: AtomicUsize = AtomicUsize::new(0);
+static PEAK: AtomicUsize = AtomicUsize::new(0);
+
+fn allocated(bytes: usize) {
+    PEAK.fetch_max(LIVE.fetch_add(bytes, Relaxed) + bytes, Relaxed);
+}
+
+// The allocator is confined to this test executable. Every allocation is 
tracked,
+// including those made before measurement, so deallocation cannot underflow 
LIVE.
+unsafe impl GlobalAlloc for CountingAllocator {
+    unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
+        let ptr = unsafe { System.alloc(layout) };
+        if !ptr.is_null() {
+            allocated(layout.size());
+        }
+        ptr
+    }
+
+    unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
+        let ptr = unsafe { System.alloc_zeroed(layout) };
+        if !ptr.is_null() {
+            allocated(layout.size());
+        }
+        ptr
+    }
+
+    unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
+        unsafe { System.dealloc(ptr, layout) };
+        LIVE.fetch_sub(layout.size(), Relaxed);
+    }
+
+    unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, size: usize) -> 
*mut u8 {
+        let new_ptr = unsafe { System.realloc(ptr, layout, size) };
+        if !new_ptr.is_null() {
+            LIVE.fetch_sub(layout.size(), Relaxed);
+            allocated(size);
+        }
+        new_ptr
+    }
+}
+
+#[global_allocator]
+static ALLOCATOR: CountingAllocator = CountingAllocator;

Review Comment:
   I moved the round trip, empty, truncated and V1-as-V2 cases into separate 
unit tests in `spec/manifest_list/mod.rs`. I removed the integration test. The 
before/after numbers are now in the description.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to