Skip to content

Show C *callables* instead of "<native>" in Tachyon - #8

Open
maurycy wants to merge 2 commits into
mainfrom
tachyon-native-callable
Open

Show C *callables* instead of "<native>" in Tachyon#8
maurycy wants to merge 2 commits into
mainfrom
tachyon-native-callable

Conversation

@maurycy

@maurycy maurycy commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Shortly:

  • no full C stack, only the frame
  • numpy.dot (BLAS) etc. invisible,
  • only CALL, CALL_KW and CALL_FUNCTION_EX
  • no BINARY_OP etc.

This is the result:

maurycy@eiger cpython (tachyon-native-callable 32756e7) % ./python -m profiling.sampling run --native -d 3 /tmp/nat.py
Captured 3,001 samples in 3.00 seconds
Sample rate: 1,000.33 samples/sec
Error rate: 0.07
Profile Stats:
       nsamples   sample%   tottime (s)    cumul%   cumtime (s)  filename:lineno(function)
      2977/2977      99.3         2.977      99.3         2.977  ~:0(time.sleep)
          20/20       0.7         0.020       0.7         0.020  nat.py:7(<module>)
         1/2978       0.0         0.001      99.3         2.978  nat.py:3(cb)
         1/2979       0.0         0.001      99.3         2.979  ~:0(sorted)
         0/2979       0.0         0.000      99.3         2.979  nat.py:6(<module>)
         0/2999       0.0         0.000     100.0         2.999  ~:0(exec)
         0/2999       0.0         0.000     100.0         2.999  <frozen runpy>:87(_run_code)
         0/2999       0.0         0.000     100.0         2.999  <frozen runpy>:201(_run_module_as_main)
         0/2999       0.0         0.000     100.0         2.999  ~:0(<native>)

Legend:
  nsamples: Direct/Cumulative samples (direct executing / on call stack)
  sample%: Percentage of total samples this function was directly executing
  tottime: Estimated total time spent directly in this function
  cumul%: Percentage of total samples when this function was on the call stack
  cumtime: Estimated cumulative time (including time in called functions)
  filename:lineno(function): Function location and name
  
Summary of Interesting Functions:
  
Functions with Highest Direct/Cumulative Ratio (Hot Spots):
  1.000 direct/cumulative ratio, 99.3% direct samples: ~:(time.sleep)
  0.007 direct/cumulative ratio, 0.7% direct samples: nat.py:(<module>)
  0.000 direct/cumulative ratio, 0.0% direct samples: nat.py:(cb)
  
Functions with Highest Call Frequency (Indirect Calls):
  2999 indirect calls, 100.0% total stack presence: ~:(exec)
  2999 indirect calls, 100.0% total stack presence: <frozen runpy>:(_run_code)
  2999 indirect calls, 100.0% total stack presence: <frozen runpy>:(_run_module_as_main)

Functions with Highest Call Magnification (Cumulative/Direct):
  2979.0x call magnification, 2978 indirect calls from 1 direct: ~:(sorted)
  2978.0x call magnification, 2977 indirect calls from 1 direct: nat.py:(cb)
  149.9x call magnification, 2979 indirect calls from 20 direct: nat.py:(<module>)
maurycy@eiger cpython (tachyon-native-callable 32756e7) % 

for:

import time
def cb(x):
    time.sleep(0.005)
    return x
while True:
    sorted([2, 1], key=cb)
    "x" * 1000000

Comment on lines +308 to +315
#define CALLABLE_HEADER_SIZE \
(offsetof(PyWrapperDescrObject, d_base) + sizeof(void *))
_Static_assert(offsetof(PyCFunctionObject, m_module) + sizeof(void *) <=
CALLABLE_HEADER_SIZE,
"PyCFunctionObject fields must fit in the callable header");
_Static_assert(offsetof(PyMethodDescrObject, d_method) + sizeof(void *) <=
CALLABLE_HEADER_SIZE,
"PyMethodDescrObject fields must fit in the callable header");

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

We don't have debug offsets. The same comment around all offsetof occurences.

@maurycy

maurycy commented Aug 29, 2026

Copy link
Copy Markdown
Owner Author

@pablogsal Does this make directional sense to you? Please do not review this yet. This is mostly a proof concept. The prime problems are a) we don't have debug offsets here so it relies on elaborate offsetof - similarly in other places, b) this is only for callables.

@maurycy maurycy self-assigned this Aug 29, 2026
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.

1 participant