-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reorder structure fields to put commonly-used fields first: quick wins #4747
Comments
Note: A first step should be ordering fields by size to get as many of them as possible accessible through an immediate offset from the base. Only if that leads to the conclusion that a single immediate offset cannot cover the whole structure it is necessary to resort to reasoning about frequency of use. |
I'm not sure I agree with this reasoning. I mean, I obviously agree that this is not something we want to do in an LTS, but I disagree that a consequence is we want to do it in 2.2x before it becomes an LTS - we can also simply not do it in 2.2x and only do it in the 3.x line.
|
Compared to other higher wins from #3535 (comment), this one breaks the ABI (many don't because they add new compile-time options), is broadly applicable (applies to every TLS user, as opposed to making features optional which only help users who don't need these features), doesn't add a maintenance burden (many of the items on that list are things we probably won't ever do because they make the code too complex), requires little prior knowledge (most of the others require surgical intervention inside the SSL stack), and has a result that's easy to review. So it's a good candidate for a new joiner, hobbyist or Friday afternoon activity. In terms of effort vs win, it beats everything else on that list. |
Those are all good points indeed. Considering these reasons I agree it makes sense to have this issue in the pre-LTS EPIC without it being the start of an endless feature creep. |
There are advantages to grouping commonly-used fields in structures together. On Cortex-M0, an access to the first 128 elements of a structure (
p->x
whenoffsetof(t, x) / sizeof(x) < 128
wheresizeof(x)
is 1, 2 or 4) uses less code than an access beyond this boundary. On platforms with a cache, putting commonly-used fields in the same cache line optimizes cache use.Anecdotal evidence suggests that in some structures, such as the SSL context, the placement of a new field can make hundreds of bytes of difference in the size of the library. In terms of effort per byte, this is a very nice win.
Note that when reordering fields, we should avoid creating holes due to padding on typical architectures, since these holes are both wasted RAM and wasted space in the “easy access” region.
Hanno writes:
The goal of this issue is to identify and perform some quick wins. I expect to at least move a few fields around in
mbedtls_ssl_context
andmbedtls_ssl_config
. The wins should be visible in the sizes reported bytests/scripts/all.sh build_arm_none_eabi_gcc_m0plus
.I also expect some ideas on how to progress further: how might we measure which fields are the most commonly used? Which structures are large enough for this to matter? Observations and suggestions should be recorded and filed for a follow-up that would do some less quick wins.
This should be done before the 2.2x LTS since we try not to change the ABI in an LTS.
The text was updated successfully, but these errors were encountered: