• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

facet-rs / facet / 19993677870

06 Dec 2025 08:12PM UTC coverage: 58.752% (+0.05%) from 58.705%
19993677870

push

github

fasterthanlime
Reduce/cordon bloat in facet, introduce bloatbench

Looks into codegen size, compile times etc. - again :) after adding a buuuunch of features.

- [x] Disable miette's default features (derive, which depends on syn) (`b.miette`)
- [x] Don't enable miette fancy by default in facet-json (`b.miette-fancy`)
- [x] Flatten closures in facet-json to avoid generic instantiations (`b.flatten-closures`)
- [x] Get rid of shape_of in Shape derive, use `#field_type` directly (`b.shape-of`)
- [x] Detect known derives in facet-macros, eschew impls! for them (`b.detect-derives`)
- [x] Gate nonzero impls, net impls (`b.gate-impls`)
- [x] Gate doc-comments, vtable-fmt, vtable-cmp, vtable-hash (`b.gate-vtable`)
- [x] Make 'auto trait detection' opt-in (`b.auto-traits-optin`)
- [x] Detect traits from `derive` and from `#[facet(default)]` (`b.derive-traits`)
- [x] Allow manual trait specification via `#[facet(traits(...))]` (`b.manual-traits`)
- [x] Go back to builders (they expand to less code) (`b.builders`)
- [x] VTable restructured with sub-vtables (`format`, `cmp`, `hash`, `markers`) (`b.vtable-substruct`)
- [x] Convert manual impls to ShapeBuilder (`scalar.rs`, `fn_ptr.rs`, `impls_num_complex.rs`) (`b.shapebuilder`)
- [x] **Confirmed**: `#![allow(uncommon_codepoints, nonstandard_style)]` in library = no warnings in consumers (`b.unicode-test`)
- [x] Add `FieldBuilder::new(name, shape_fn, offset)` builder (`b.field-builder`)
- [x] Add `StructTypeBuilder::new(kind, fields)` builder (`b.structtype-builder`)
- [x] Add `VariantBuilder::new(name, data)` builder (`b.variant-builder`)
- [x] Add `EnumTypeBuilder::new(enum_repr, variants)` builder (`b.enumtype-builder`)
- [x] Create `::facet::𝟋` module with type aliases and builder exports (`b.prelude-mod`)
- [x] Update derive macro to use builder pattern for Field, StructType, Variant, EnumType (`b.derive-builders`)

Based on analysis in `facet-bloatbench/MACRO-OPTIMIZATION-ANALYSIS.md`:

- [x] Remove `let mut vtable = const... (continued)

1199 of 3227 new or added lines in 72 files covered. (37.16%)

145 existing lines in 29 files now uncovered.

24253 of 41280 relevant lines covered (58.75%)

504.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.0
/facet-core/src/impls_alloc/vec.rs
1
use core::ptr::NonNull;
2

3
use crate::shape_util::vtable_for_list;
4
use crate::*;
5

6
use alloc::boxed::Box;
7
use alloc::vec::Vec;
8

9
type VecIterator<'mem, T> = core::slice::Iter<'mem, T>;
10

11
unsafe impl<'a, T> Facet<'a> for Vec<T>
12
where
13
    T: Facet<'a>,
14
{
15
    const SHAPE: &'static Shape = &const {
16
        Shape {
17
            id: Shape::id_of::<Self>(),
18
            layout: Shape::layout_of::<Self>(),
19
            vtable: ValueVTable {
20
                type_name: |f, opts| {
206✔
21
                    if let Some(opts) = opts.for_children() {
206✔
22
                        write!(f, "{}<", Self::SHAPE.type_identifier)?;
206✔
23
                        T::SHAPE.vtable.type_name()(f, opts)?;
206✔
24
                        write!(f, ">")
206✔
25
                    } else {
NEW
26
                        write!(f, "{}<…>", Self::SHAPE.type_identifier)
×
27
                    }
28
                },
206✔
29
                default_in_place: Some(|target| unsafe { target.put(Self::default()) }),
2✔
30
                ..vtable_for_list::<T, Self>()
31
            },
32
            ty: Type::User(UserType::Opaque),
33
            def: Def::List(ListDef::new(
34
                &const {
35
                    ListVTable {
36
                        init_in_place_with_capacity: Some(|data, capacity| unsafe {
37
                            data.put(Self::with_capacity(capacity))
235✔
38
                        }),
235✔
39
                        push: Some(|ptr, item| unsafe {
40
                            let vec = ptr.as_mut::<Self>();
12,773✔
41
                            let item = item.read::<T>();
12,773✔
42
                            (*vec).push(item);
12,773✔
43
                        }),
12,773✔
44
                        len: |ptr| unsafe {
45
                            let vec = ptr.get::<Self>();
219✔
46
                            vec.len()
219✔
47
                        },
219✔
48
                        get: |ptr, index| unsafe {
49
                            let vec = ptr.get::<Self>();
26✔
50
                            let item = vec.get(index)?;
26✔
51
                            Some(PtrConst::new(NonNull::from(item)))
24✔
52
                        },
26✔
53
                        get_mut: Some(|ptr, index| unsafe {
NEW
54
                            let vec = ptr.as_mut::<Self>();
×
NEW
55
                            let item = vec.get_mut(index)?;
×
NEW
56
                            Some(PtrMut::new(NonNull::from(item)))
×
NEW
57
                        }),
×
58
                        as_ptr: Some(|ptr| unsafe {
59
                            let vec = ptr.get::<Self>();
151✔
60
                            PtrConst::new(NonNull::new_unchecked(vec.as_ptr() as *mut T))
151✔
61
                        }),
151✔
62
                        as_mut_ptr: Some(|ptr| unsafe {
NEW
63
                            let vec = ptr.as_mut::<Self>();
×
NEW
64
                            PtrMut::new(NonNull::new_unchecked(vec.as_mut_ptr()))
×
NEW
65
                        }),
×
66
                        iter_vtable: {
67
                            IterVTable {
68
                                init_with_value: Some(|ptr| unsafe {
UNCOV
69
                                    let vec = ptr.get::<Self>();
×
NEW
70
                                    let iter: VecIterator<T> = vec.iter();
×
NEW
71
                                    let iter_state = Box::new(iter);
×
NEW
72
                                    PtrMut::new(NonNull::new_unchecked(
×
NEW
73
                                        Box::into_raw(iter_state) as *mut u8
×
74
                                    ))
NEW
75
                                }),
×
76
                                next: |iter_ptr| unsafe {
NEW
77
                                    let state = iter_ptr.as_mut::<VecIterator<'_, T>>();
×
NEW
78
                                    state
×
NEW
79
                                        .next()
×
NEW
80
                                        .map(|value| PtrConst::new(NonNull::from(value)))
×
NEW
81
                                },
×
82
                                next_back: Some(|iter_ptr| unsafe {
NEW
83
                                    let state = iter_ptr.as_mut::<VecIterator<'_, T>>();
×
NEW
84
                                    state
×
NEW
85
                                        .next_back()
×
NEW
86
                                        .map(|value| PtrConst::new(NonNull::from(value)))
×
NEW
87
                                }),
×
88
                                size_hint: None,
89
                                dealloc: |iter_ptr| unsafe {
NEW
90
                                    drop(Box::from_raw(iter_ptr.as_ptr::<VecIterator<'_, T>>()
×
NEW
91
                                        as *mut VecIterator<'_, T>));
×
NEW
92
                                },
×
93
                            }
94
                        },
95
                    }
96
                },
97
                T::SHAPE,
98
            )),
99
            type_identifier: "Vec",
100
            type_params: &[TypeParam {
101
                name: "T",
102
                shape: T::SHAPE,
103
            }],
104
            doc: &[],
105
            attributes: &[],
106
            type_tag: None,
107
            inner: None,
108
        }
109
    };
110
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc