Skip to content

Commit 0c3614a

Browse files
fixup! Store Tachyon samples in bounded columnar blocks
Choose and write stack instructions in write_stack() instead of passing the decision and four related values through a separate helper. This keeps each encoding path together and removes an unreachable fallback.
1 parent 5db16aa commit 0c3614a

1 file changed

Lines changed: 23 additions & 44 deletions

File tree

‎Modules/_remote_debugging/binary_io_writer.c‎

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -922,59 +922,38 @@ write_stack_replace_suffix(BinaryWriter *writer, StackCacheEntry *bucket,
922922
return 0;
923923
}
924924

925-
static int
926-
choose_stack_encoding(SampleBlock *block, const ThreadEntry *entry,
927-
int new_stream, const uint32_t *stack, size_t depth,
928-
size_t *shared, Py_uhash_t *hash,
929-
StackCacheEntry **bucket, StackCacheEntry **cached)
930-
{
931-
*shared = common_outer_frames(entry, stack, depth);
932-
*hash = 0;
933-
*bucket = NULL;
934-
*cached = NULL;
935-
if (!new_stream && *shared == depth &&
936-
*shared == entry->prev_stack_depth) {
937-
return STACK_REPEAT;
938-
}
939-
if (depth - *shared < STACK_REUSE_MIN_FRAMES) {
940-
return STACK_REPLACE_SUFFIX;
941-
}
942-
*hash = stack_hash(stack, depth);
943-
*bucket = block->cache[*hash % STACK_CACHE_BUCKET_COUNT];
944-
*cached = stack_cache_lookup(*bucket, &block->columns[COLUMN_FRAME_IDS],
945-
*hash, stack, depth);
946-
if (*cached != NULL) {
947-
return STACK_REUSE;
948-
}
949-
return STACK_REPLACE_SUFFIX;
950-
}
951-
952925
static int
953926
write_stack(BinaryWriter *writer, ThreadEntry *entry, int new_stream,
954927
const uint32_t *stack, size_t depth)
955928
{
956-
size_t shared;
957-
Py_uhash_t hash;
958-
StackCacheEntry *bucket;
959-
StackCacheEntry *cached;
960-
int encoding = choose_stack_encoding(writer->block, entry, new_stream,
961-
stack, depth, &shared, &hash,
962-
&bucket, &cached);
929+
SampleBlock *block = writer->block;
930+
size_t shared = common_outer_frames(entry, stack, depth);
931+
/* Same stack as this stream's previous sample: extend its REPEAT */
932+
if (!new_stream && shared == depth &&
933+
shared == entry->prev_stack_depth) {
934+
return write_stack_repeat(writer, entry, depth);
935+
}
936+
937+
/* Enough new frames to be worth looking up an earlier complete stack */
938+
Py_uhash_t hash = 0;
939+
StackCacheEntry *bucket = NULL;
940+
StackCacheEntry *cached = NULL;
941+
if (depth - shared >= STACK_REUSE_MIN_FRAMES) {
942+
hash = stack_hash(stack, depth);
943+
bucket = block->cache[hash % STACK_CACHE_BUCKET_COUNT];
944+
cached = stack_cache_lookup(bucket, &block->columns[COLUMN_FRAME_IDS],
945+
hash, stack, depth);
946+
}
963947

964948
int result;
965-
switch (encoding) {
966-
case STACK_REPEAT:
967-
return write_stack_repeat(writer, entry, depth);
968-
case STACK_REUSE:
949+
if (cached != NULL) {
950+
/* Stack already stored in this block: point to its frames */
969951
result = write_stack_reuse(writer, cached, depth);
970-
break;
971-
case STACK_REPLACE_SUFFIX:
952+
}
953+
else {
954+
/* Keep the shared outer frames and write only the new inner ones */
972955
result = write_stack_replace_suffix(writer, bucket, hash, stack,
973956
depth, shared);
974-
break;
975-
default:
976-
PyErr_SetString(PyExc_RuntimeError, "Invalid stack encoding type");
977-
return -1;
978957
}
979958
if (result < 0) {
980959
return -1;

0 commit comments

Comments
 (0)