Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e8e0a39

Browse files
davidbencommit-bot@chromium.org
authored andcommitted
Estimate the overhead of an X509 object without sizeof
To unblock optimizations in hopes of reducing the overhead, we're planning to make X509 opaque in BoringSSL. This aligns with upstream OpenSSL, which has made most of these structs opaque. Instead, use an estimate. The sizeof-based estimate was undercounting the overhead anyway because there are many structures underneath X509, some of which are already opaque. I just rounded sizeof(X509) + sizeof(X509_CINF) up. (Even this is likely still undercounting it because X509 objects are very malloc-heavy and duplicate large chunks of the certificate. They're not a very efficient representation and can't be made efficient without first hiding the structs. In Chrome, we stopped using them altogether and just retain the byte string, parsing as needed.) TEST=ci Change-Id: Icdc729ceba7eadf002bec5e080fc3e0adf7c4b56 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209920 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Alexander Aprelev <[email protected]> Auto-Submit: David Benjamin <[email protected]>
1 parent cc84bb3 commit e8e0a39

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

runtime/bin/security_context.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ static void ReleaseCertificate(void* isolate_data, void* context_pointer) {
122122

123123
static intptr_t EstimateX509Size(X509* certificate) {
124124
intptr_t length = i2d_X509(certificate, NULL);
125-
return length > 0 ? length : 0;
125+
length = length > 0 ? length : 0;
126+
// An X509 is a tree of structures, which are either opaque or will be opaque
127+
// in the future. Estimate the overhead to 512 bytes by rounding up
128+
// sizeof(X509) + sizeof(X509_CINF).
129+
return length + 512;
126130
}
127131

128132
// Returns the handle for a Dart object wrapping the X509 certificate object.
@@ -154,7 +158,7 @@ Dart_Handle X509Helper::WrappedX509Certificate(X509* certificate) {
154158
return status;
155159
}
156160
const intptr_t approximate_size_of_certificate =
157-
sizeof(*certificate) + EstimateX509Size(certificate);
161+
EstimateX509Size(certificate);
158162
ASSERT(approximate_size_of_certificate > 0);
159163
Dart_NewFinalizableHandle(result, reinterpret_cast<void*>(certificate),
160164
approximate_size_of_certificate,

0 commit comments

Comments
 (0)