Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
082b076
excise OLD_API
ludamad Oct 7, 2025
0132507
wasm
ludamad Oct 8, 2025
7d5f8d9
clean up wasm
ludamad Oct 8, 2025
ab603c0
Merge branch 'merge-train/barretenberg' into ad/wasmtime-experiments
ludamad Oct 8, 2025
225b73f
small schema_compiler.ts fixes
ludamad Oct 8, 2025
474e0bc
Merge remote-tracking branch 'origin/ad/wasmtime-experiments' into ad…
ludamad Oct 8, 2025
7b8ad58
Discard changes to barretenberg/ts/src/cbind/schema_compiler.ts
ludamad Oct 12, 2025
6fbd244
feat: enable BB_BENCH benchmarking in WASM via compile-time flag
ludamad Oct 14, 2025
0d6e3d4
Merge remote-tracking branch 'origin/merge-train/barretenberg' into a…
ludamad Oct 14, 2025
ac2ac68
chore: update ci_benchmark_ivc_flows.sh to use wasm-threads-bench build
ludamad Oct 14, 2025
69a55f9
feat: add --print_bench support for WASM with ENABLE_WASM_BENCH
ludamad Oct 14, 2025
8a3dd1f
Merge branch 'merge-train/barretenberg' into ad/wasmtime-experiments
ludamad Oct 15, 2025
3ec6448
Merge branch 'merge-train/barretenberg' into ad/wasmtime-experiments
ludamad Oct 25, 2025
1c02269
fix: resolve type mismatch in bb_bench.cpp std::max calls
ludamad Oct 25, 2025
77cfad9
fix: add missing #endif in bb_bench.cpp
ludamad Oct 25, 2025
d6018fe
fix: use uint64_t in SerializableEntry to avoid narrowing conversion
ludamad Oct 25, 2025
064ae99
fix: enable storage_budget symbols for WASM builds with ENABLE_WASM_B…
ludamad Oct 25, 2025
c6f730f
fix: provide no-exceptions version of parse_size_string for WASM builds
ludamad Oct 26, 2025
61d65dd
chore(bb): replace wasm-threads-bench preset with ENABLE_WASM_BENCH C…
ludamad Oct 26, 2025
d89ed89
chore(bb): auto-enable ENABLE_WASM_BENCH for non-semver WASM builds
ludamad Oct 26, 2025
becdfc5
chore(bb): move ENABLE_WASM_BENCH auto-enable to specific build funct…
ludamad Oct 26, 2025
1d85f96
chore(bb): export wasm_cmake_args at top of bootstrap script
ludamad Oct 26, 2025
5d9ad8a
chore(bb): move ENABLE_WASM_BENCH logic into build_preset function
ludamad Oct 26, 2025
91c93f7
Update bootstrap.sh
ludamad Oct 27, 2025
b56b959
Merge branch 'merge-train/barretenberg' into ad/wasmtime-experiments
ludamad Oct 27, 2025
60ba692
Update bootstrap.sh
ludamad Oct 27, 2025
484cd49
Merge branch 'merge-train/barretenberg' into ad/wasmtime-experiments
ludamad Oct 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions barretenberg/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ option(ENABLE_STACKTRACES "Enable stack traces on assertion" OFF)
option(ENABLE_TRACY "Enable low-medium overhead profiling for memory and performance with tracy" OFF)
option(ENABLE_PIC "Builds with position independent code" OFF)
option(SYNTAX_ONLY "only check syntax (-fsyntax-only)" OFF)
option(ENABLE_WASM_BENCH "Enable BB_BENCH benchmarking support in WASM builds (dev only, not for releases)" OFF)
option(AVM "enable building of vm2 module and bb-avm" ON)

if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
Expand Down Expand Up @@ -97,6 +98,10 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "wasm32")
set(OMP_MULTITHREADING OFF)
set(ENABLE_PAR_ALGOS 0)
add_compile_definitions(_WASI_EMULATED_PROCESS_CLOCKS=1)
if(ENABLE_WASM_BENCH)
message(STATUS "Enabling WASM benchmarking support (ENABLE_WASM_BENCH)")
add_compile_definitions(ENABLE_WASM_BENCH)
endif()
endif()

set(CMAKE_C_STANDARD 11)
Expand Down
10 changes: 7 additions & 3 deletions barretenberg/cpp/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ function inject_version {
function build_preset() {
local preset=$1
shift
local avm_transpiler_flag=""
local cmake_args=()
if [ "${AVM_TRANSPILER:-1}" -eq 0 ]; then
avm_transpiler_flag="-DAVM_TRANSPILER_LIB="
cmake_args+=(-DAVM_TRANSPILER_LIB=)
fi
cmake --fresh --preset "$preset" $avm_transpiler_flag
# Auto-enable ENABLE_WASM_BENCH for wasm-threads preset on non-semver builds
if [[ "$preset" == "wasm-threads" ]] && ! semver check "$REF_NAME"; then
cmake_args+=(-DENABLE_WASM_BENCH=ON)
fi
cmake --fresh --preset "$preset" "${cmake_args[@]}"
cmake --build --preset "$preset" "$@"
}

Expand Down
1 change: 1 addition & 0 deletions barretenberg/cpp/scripts/wasmtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exec wasmtime run \
${HARDWARE_CONCURRENCY:+--env HARDWARE_CONCURRENCY} \
--env HOME \
${MAIN_ARGS:+--env MAIN_ARGS} \
${BB_BENCH:+--env BB_BENCH} \
--dir=$HOME/.bb-crs \
--dir=. \
"$@"
9 changes: 6 additions & 3 deletions barretenberg/cpp/src/barretenberg/bb/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,12 +553,13 @@ int parse_and_run_cli_command(int argc, char* argv[])
debug_logging = flags.debug;
verbose_logging = debug_logging || flags.verbose;
slow_low_memory = flags.slow_low_memory;
#ifndef __wasm__
#if !defined(__wasm__) || defined(ENABLE_WASM_BENCH)
if (!flags.storage_budget.empty()) {
storage_budget = parse_size_string(flags.storage_budget);
}
if (print_bench || !bench_out.empty() || !bench_out_hierarchical.empty()) {
bb::detail::use_bb_bench = true;
vinfo("BB_BENCH enabled via --print_bench or --bench_out");
}
#endif

Expand Down Expand Up @@ -649,9 +650,11 @@ int parse_and_run_cli_command(int argc, char* argv[])
"<ivc-inputs.msgpack> (default ./ivc-inputs.msgpack)");
}
api.prove(flags, ivc_inputs_path, output_path);
#ifndef __wasm__
#if !defined(__wasm__) || defined(ENABLE_WASM_BENCH)
if (print_bench) {
vinfo("Printing BB_BENCH results...");
bb::detail::GLOBAL_BENCH_STATS.print_aggregate_counts_hierarchical(std::cout);
std::cout << std::flush;
}
if (!bench_out.empty()) {
std::ofstream file(bench_out);
Expand All @@ -677,7 +680,7 @@ int parse_and_run_cli_command(int argc, char* argv[])
UltraHonkAPI api;
if (prove->parsed()) {
api.prove(flags, bytecode_path, witness_path, vk_path, output_path);
#ifndef __wasm__
#if !defined(__wasm__) || defined(ENABLE_WASM_BENCH)
if (print_bench) {
bb::detail::GLOBAL_BENCH_STATS.print_aggregate_counts_hierarchical(std::cout);
}
Expand Down
14 changes: 7 additions & 7 deletions barretenberg/cpp/src/barretenberg/common/bb_bench.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "barretenberg/common/assert.hpp"
#include <cstdint>
#include <sys/types.h>
#ifndef __wasm__
#if !defined(__wasm__) || defined(ENABLE_WASM_BENCH)
#include "barretenberg/serialize/msgpack_impl.hpp"
#include "bb_bench.hpp"
#include <algorithm>
Expand Down Expand Up @@ -182,7 +182,7 @@ void AggregateEntry::add_thread_time_sample(const TimeAndCount& stats)
// Account for aggregate time and count
time += stats.time;
count += stats.count;
time_max = std::max(static_cast<size_t>(stats.time), time_max);
time_max = std::max(stats.time, time_max);
// Use Welford's method to be able to track the variance
num_threads++;
double delta = static_cast<double>(stats.time) - time_mean;
Expand Down Expand Up @@ -300,12 +300,12 @@ void GlobalBenchStatsContainer::print_aggregate_counts(std::ostream& os, size_t
// Serializable structure for a single benchmark entry (msgpack-compatible)
struct SerializableEntry {
std::string parent;
std::size_t time;
std::size_t time_max;
uint64_t time;
uint64_t time_max;
double time_mean;
double time_stddev;
std::size_t count;
std::size_t num_threads;
uint64_t count;
uint64_t num_threads;

MSGPACK_FIELDS(parent, time, time_max, time_mean, time_stddev, count, num_threads);
};
Expand Down Expand Up @@ -578,7 +578,7 @@ void GlobalBenchStatsContainer::print_aggregate_counts_hierarchical(std::ostream
uint64_t total_time = 0;
for (const auto& [_, parent_map] : aggregated) {
if (auto it = parent_map.find(""); it != parent_map.end()) {
total_time = std::max(static_cast<size_t>(total_time), it->second.time_max);
total_time = std::max(total_time, it->second.time_max);
}
}

Expand Down
20 changes: 10 additions & 10 deletions barretenberg/cpp/src/barretenberg/common/bb_bench.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ struct AggregateEntry {
// For convenience, even though redundant with map store
OperationKey key;
OperationKey parent;
std::size_t time = 0;
std::size_t count = 0;
uint64_t time = 0;
uint64_t count = 0;
size_t num_threads = 0;
double time_mean = 0;
std::size_t time_max = 0;
uint64_t time_max = 0;
double time_stddev = 0;

// Welford's algorithm state
Expand Down Expand Up @@ -106,19 +106,19 @@ extern GlobalBenchStatsContainer GLOBAL_BENCH_STATS;
// but doesn't provide recursive parent-child relationships through the entire call stack.
struct TimeStats {
TimeStatsEntry* parent = nullptr;
std::size_t count = 0;
std::size_t time = 0;
uint64_t count = 0;
uint64_t time = 0;
// Used if the parent changes from last call - chains to handle multiple parent contexts
std::unique_ptr<TimeStats> next;

TimeStats() = default;
TimeStats(TimeStatsEntry* parent_ptr, std::size_t count_val, std::size_t time_val)
TimeStats(TimeStatsEntry* parent_ptr, uint64_t count_val, uint64_t time_val)
: parent(parent_ptr)
, count(count_val)
, time(time_val)
{}

void track(TimeStatsEntry* current_parent, std::size_t time_val)
void track(TimeStatsEntry* current_parent, uint64_t time_val)
{
// Try to track with current stats if parent matches
// Check if 'next' already handles this parent to avoid creating duplicates
Expand All @@ -138,7 +138,7 @@ struct TimeStats {

private:
// Returns true if successfully tracked (parent matches), false otherwise
bool raw_track(TimeStatsEntry* expected_parent, std::size_t time_val)
bool raw_track(TimeStatsEntry* expected_parent, uint64_t time_val)
{
if (parent != expected_parent) {
return false;
Expand Down Expand Up @@ -181,7 +181,7 @@ template <OperationLabel Op> struct ThreadBenchStats {
struct BenchReporter {
TimeStatsEntry* parent;
TimeStatsEntry* stats;
std::size_t time;
uint64_t time;
BenchReporter(TimeStatsEntry* entry);
~BenchReporter();
};
Expand All @@ -196,7 +196,7 @@ struct BenchReporter {
#define BB_BENCH_ONLY_NAME(name) (void)0
#define BB_BENCH_ENABLE_NESTING() (void)0
#define BB_BENCH_ONLY() (void)0
#elif defined __wasm__
#elif defined __wasm__ && !defined ENABLE_WASM_BENCH
#define BB_TRACY() (void)0
#define BB_TRACY_NAME(name) (void)0
#define BB_BENCH_TRACY() (void)0
Expand Down
17 changes: 14 additions & 3 deletions barretenberg/cpp/src/barretenberg/polynomials/backing_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@
bool slow_low_memory =
std::getenv("BB_SLOW_LOW_MEMORY") == nullptr ? false : std::string(std::getenv("BB_SLOW_LOW_MEMORY")) == "1";

// Storage budget is disabled for WASM builds
#ifndef __wasm__
// Storage budget is disabled for WASM builds unless ENABLE_WASM_BENCH is defined
#if !defined(__wasm__) || defined(ENABLE_WASM_BENCH)

#if defined(__wasm__) && defined(BB_NO_EXCEPTIONS)
// Simplified version for WASM builds without exception support
// For WASM benchmarking, we don't enforce storage budgets
size_t parse_size_string(const std::string& /* size_str */)
{
// Return unlimited budget for WASM builds
return std::numeric_limits<size_t>::max();
}
#else
// Full version with exception handling for native builds
// Parse storage size string (e.g., "500m", "2g", "1024k")
size_t parse_size_string(const std::string& size_str)
{
Expand Down Expand Up @@ -55,6 +65,7 @@ size_t parse_size_string(const std::string& size_str)
throw_or_abort("Invalid storage size format: '" + size_str + "'. Value out of range");
}
}
#endif

namespace {
// Parse storage budget from environment variable (supports k/m/g suffixes like Docker)
Expand All @@ -75,4 +86,4 @@ size_t storage_budget = parse_storage_budget();
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
std::atomic<size_t> current_storage_usage{ 0 };

#endif // __wasm__
#endif // !defined(__wasm__) || defined(ENABLE_WASM_BENCH)
Loading