Skip to content

Add profiling#199

Merged
Chris7 merged 2 commits into
mainfrom
add-profiler
Jun 26, 2026
Merged

Add profiling#199
Chris7 merged 2 commits into
mainfrom
add-profiler

Conversation

@Chris7

@Chris7 Chris7 commented Jun 24, 2026

Copy link
Copy Markdown
Member

Adds a profiling command to identify slow points in the codebase. Adds instrumentation for some functions so they can be profiled. There are 2 profile modes: instrumentation which tracks things with the cfg profile attribute, and a sample based profiler.

profiler is enabled by building with --features profiling

@Chris7 Chris7 requested a review from dkhofer June 24, 2026 20:36
Comment thread bin/benchmark.sh
get_size () {
local filesize_mb=$(python -c "import os;size=os.path.getsize('${GEN_DIR}/default.db') / (1024 * 1024);print(f'{size:.4f}')")
echo $filesize_mb
GEN_DIR="${GEN_DIR}" GEN_DB_PATH="${GEN_DIR}/gen.db" DEFAULT_DB_PATH="${GEN_DIR}/default.db" ${PYTHON_BIN} -c "import os

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to do all this with system commands, instead of invoking python?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's this way just for portability of code between systems

Comment thread bin/benchmark.sh

time_taken() {
local start_time=$(python -c "import time;print(round(time.time()*1000))")
local start_time=$(${PYTHON_BIN} -c "import time;print(round(time.time()*1000))")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the system command date +%s%N gives time in nanoseconds?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not natively supported in osx

Comment thread bin/benchmark.sh
read -r BOTH_SIZE BOTH_GEN_DB_SIZE BOTH_DEFAULT_DB_SIZE <<< "$(get_size)"
record_result "HG00096 + HG00097 Update" "${SUM}" "${BOTH_SIZE}" "${BOTH_GEN_DB_SIZE}" "${BOTH_DEFAULT_DB_SIZE}"

# echo "switch branch benchmark"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these commented out? Is the idea to uncomment to benchmark specific ones?

Comment thread src/profiling.rs
.iter()
.map(|(stack, stat)| (stack_frames(stack), stat.calls, stat.total))
.collect::<Vec<_>>();
rows.sort_by(|left, right| right.2.cmp(&left.2).then_with(|| left.0.cmp(&right.0)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to add a comment saying what fields 0 and 2 are

Comment thread src/profiling.rs Outdated
where
S: Subscriber + for<'span> LookupSpan<'span>,
{
fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nitpick: ctx -> context

Comment thread src/profiling.rs
starts: Vec<Instant>,
}

impl Profiler {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a comment somewhere saying what the difference is between the Profiler and the SampleProfiler? Maybe add a docstring to each class?

@dkhofer dkhofer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, just a few comments

@Chris7 Chris7 merged commit a3ba386 into main Jun 26, 2026
6 of 7 checks passed
@Chris7 Chris7 deleted the add-profiler branch June 26, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants