Skip to content

Commit 2addc70

Browse files
committed
clean up and use nonzerou64
Signed-off-by: Connor Tsui <[email protected]>
1 parent 5139fc4 commit 2addc70

File tree

4 files changed

+14
-281
lines changed

4 files changed

+14
-281
lines changed

vortex-wasm/src/bin/test_s3_read.rs

Lines changed: 0 additions & 56 deletions
This file was deleted.

vortex-wasm/src/bin/test_s3_update.rs

Lines changed: 0 additions & 147 deletions
This file was deleted.

vortex-wasm/src/website/charts.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4+
use std::num::NonZeroU64;
5+
46
use serde::Serialize;
57
use vortex::utils::aliases::hash_map::HashMap;
68
use vortex_error::VortexResult;
@@ -29,13 +31,11 @@ pub struct BenchmarkGroupData {
2931
pub charts: HashMap<String, ChartData>,
3032
}
3133

32-
// TODO(connor): We should be able to use an `Option<NonZeroU64>` since our benchmarks should
33-
// basically never hit 0, but that is an optimization for another day.
3434
/// Chart data.
3535
#[derive(Debug, Clone, Serialize)]
3636
pub struct ChartData {
3737
/// The name of a series and its associated data.
38-
pub aligned_series: HashMap<String, Vec<Option<u64>>>,
38+
pub aligned_series: HashMap<String, Vec<Option<NonZeroU64>>>,
3939
}
4040

4141
// ============================================================================
@@ -145,10 +145,19 @@ pub fn process_benchmarks(
145145
fn create_aligned_series_data(
146146
commits_and_values: CommitValueMap<'_>,
147147
sorted_commits: &[CommitInfo],
148-
) -> Vec<Option<u64>> {
148+
) -> Vec<Option<NonZeroU64>> {
149149
sorted_commits
150150
.iter()
151-
.map(|commit_info| commits_and_values.get(commit_info.commit_id()).copied())
151+
.map(|commit_info| {
152+
commits_and_values
153+
.get(commit_info.commit_id())
154+
.map(|&value| {
155+
NonZeroU64::new(value).unwrap_or_else(|| {
156+
eprintln!("Warning: benchmark value of 0 encountered, converting to 1");
157+
NonZeroU64::MIN
158+
})
159+
})
160+
})
152161
.collect()
153162
}
154163

vortex-wasm/src/website/read_s3.rs

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ use vortex::file::OpenOptionsSessionExt;
1313
use vortex::session::VortexSession;
1414
use vortex_array::ArrayRef;
1515
use vortex_error::VortexExpect;
16-
use wasm_bindgen::JsValue;
1716

1817
use super::entry::BenchmarkEntry;
19-
use crate::website::charts::BenchmarkResponse;
2018
use crate::website::charts::Benchmarks;
2119
use crate::website::charts::extract_summary;
2220
use crate::website::charts::process_benchmarks;
@@ -170,74 +168,3 @@ pub async fn read_s3_array(session: &VortexSession, key: &str) -> VortexResult<A
170168

171169
file.scan()?.into_array_stream()?.read_all().await
172170
}
173-
174-
/// Reads benchmark entries from an S3 object containing a Vortex file.
175-
///
176-
/// This function downloads the Vortex file from S3 using HTTP (the bucket is public), parses the
177-
/// columnar struct array, and converts it to a vector of row-wise [`BenchmarkEntry`] structs.
178-
///
179-
/// # Arguments
180-
///
181-
/// * `session` - The Vortex session for reading files.
182-
/// * `key` - The S3 object key (e.g., "test/random_access.vortex").
183-
///
184-
/// # Errors
185-
///
186-
/// Returns an error if:
187-
/// - The HTTP request fails.
188-
/// - The file is not a valid Vortex file.
189-
/// - The schema does not match the expected [`BenchmarkEntry`] schema.
190-
pub async fn read_benchmark_entries(
191-
session: &VortexSession,
192-
key: &str,
193-
) -> VortexResult<Vec<BenchmarkEntry>> {
194-
let array = read_s3_array(session, key).await?;
195-
BenchmarkEntry::vec_from_array(&array)
196-
}
197-
198-
/// Fetches benchmark data and commit metadata from S3 and returns them as a JavaScript object.
199-
///
200-
/// The returned object has the structure:
201-
/// ```javascript
202-
/// {
203-
/// benchmarks: { [group_name]: { charts: { [chart_name]: { aligned_series: { [series_name]: [...] } } } } },
204-
/// commits: [{ timestamp, author: { name, email }, message, commit_id }, ...]
205-
/// }
206-
/// ```
207-
///
208-
/// # Arguments
209-
///
210-
/// * `session` - The Vortex session for reading files.
211-
/// * `commits_key` - S3 key for the commits Vortex file.
212-
/// * `data_key` - S3 key for the benchmark data Vortex file.
213-
///
214-
/// # Errors
215-
///
216-
/// Returns an error if:
217-
/// - Either S3 fetch fails.
218-
/// - The files are not valid Vortex files.
219-
/// - The schemas don't match expected formats.
220-
/// - Validation fails (empty names, no data points, mismatched lengths).
221-
pub async fn get_benchmark_data(
222-
session: &VortexSession,
223-
commits_key: &str,
224-
data_key: &str,
225-
) -> VortexResult<JsValue> {
226-
let (data_array, commits_array) = futures::try_join!(
227-
read_s3_array(session, data_key),
228-
read_s3_array(session, commits_key)
229-
)?;
230-
231-
let data = BenchmarkEntry::vec_from_array(&data_array)?;
232-
let mut commits = CommitInfo::vec_from_array(&commits_array)?;
233-
commits.sort_unstable();
234-
235-
let benchmarks = process_benchmarks(&data, &commits)?;
236-
let response = BenchmarkResponse {
237-
benchmarks,
238-
commits,
239-
};
240-
241-
serde_wasm_bindgen::to_value(&response)
242-
.map_err(|e| vortex_err!("Failed to serialize benchmark response: {e}"))
243-
}

0 commit comments

Comments
 (0)