Skip to content

Set types as attributes on the cstruct object#114

Open
Schamper wants to merge 3 commits intomainfrom
type-as-attr
Open

Set types as attributes on the cstruct object#114
Schamper wants to merge 3 commits intomainfrom
type-as-attr

Conversation

@Schamper
Copy link
Member

Closes #113

Some micro benchmarks:

from dissect.cstruct import cstruct

cdef = """
#define X 512

enum MyEnum {
    A,
    B,
    C
};

struct test {
    uint32 a;
};
"""
cs = cstruct()
cs.load(cdef)

Before:

In: %timeit getattr(t.cs, "X")
58.1 ns ± 1.04 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

In: %timeit getattr(t.cs, "MyEnum")
227 ns ± 0.912 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

In: %timeit getattr(t.cs, "test")
219 ns ± 1.47 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

After:

In: %timeit getattr(t.cs, "X")
31.2 ns ± 0.0331 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

In: %timeit getattr(t.cs, "MyEnum")
33.1 ns ± 0.0884 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

In: %timeit getattr(t.cs, "test")
31.3 ns ± 0.0571 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

@Schamper Schamper force-pushed the type-as-attr branch 3 times, most recently from a7a1441 to 43b6333 Compare July 3, 2025 10:19
@codecov
Copy link

codecov bot commented Jul 3, 2025

Codecov Report

❌ Patch coverage is 0% with 68 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (a282438) to head (aa1e186).

Files with missing lines Patch % Lines
dissect/cstruct/cstruct.py 0.00% 29 Missing ⚠️
dissect/cstruct/tools/stubgen.py 0.00% 25 Missing ⚠️
dissect/cstruct/parser.py 0.00% 12 Missing ⚠️
dissect/cstruct/types/structure.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #114   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         21      21           
  Lines       2435    2469   +34     
=====================================
- Misses      2435    2469   +34     
Flag Coverage Δ
unittests 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Miauwkeru
Copy link
Contributor

Some initial remarks with these changes, some projects fail to build:

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 26, 2026

Merging this PR will degrade performance by 15.45%

⚡ 3 improved benchmarks
❌ 1 regressed benchmark
✅ 4 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
test_benchmark_basic[compiled] 83.2 µs 74.8 µs +11.28%
test_benchmark_getattr_types 27.4 µs 14.4 µs +89.53%
test_benchmark_getattr_typedefs 27.8 µs 32.9 µs -15.45%
test_benchmark_getattr_constants 17.2 µs 14.4 µs +19.19%

Comparing type-as-attr (aa1e186) with main (a282438)

Open in CodSpeed

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.

Eagerly resolve types and set as attributes on the cstruct object

2 participants