| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b405e9b commit c5cb6bc
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -209,13 +209,7 @@ FSReqPromise<AliasedBufferT>::FSReqPromise(BindingData* binding_data, | |||
| 209 | 209 | v8::Local<v8::Object> obj, | |
| 210 | 210 | bool use_bigint) | |
| 211 | 211 | : FSReqBase( | |
| 212 | - binding_data, obj, AsyncWrap::PROVIDER_FSREQPROMISE, use_bigint), | ||
| 213 | - stats_field_array_( | ||
| 214 | - env()->isolate(), | ||
| 215 | - static_cast<size_t>(FsStatsOffset::kFsStatsFieldsNumber)), | ||
| 216 | - statfs_field_array_( | ||
| 217 | - env()->isolate(), | ||
| 218 | - static_cast<size_t>(FsStatFsOffset::kFsStatFsFieldsNumber)) {} | ||
| 212 | + binding_data, obj, AsyncWrap::PROVIDER_FSREQPROMISE, use_bigint) {} | ||
| 219 | 213 | ||
| 220 | 214 | template <typename AliasedBufferT> | |
| 221 | 215 | void FSReqPromise<AliasedBufferT>::Reject(v8::Local<v8::Value> reject) { | |
@@ -253,14 +247,24 @@ void FSReqPromise<AliasedBufferT>::Resolve(v8::Local<v8::Value> value) { | |||
| 253 | 247 | ||
| 254 | 248 | template <typename AliasedBufferT> | |
| 255 | 249 | void FSReqPromise<AliasedBufferT>::ResolveStat(const uv_stat_t* stat) { | |
| 256 | - FillStatsArray(&stats_field_array_, stat); | ||
| 257 | - Resolve(stats_field_array_.GetJSArray()); | ||
| 250 | + if (!stats_field_array_.has_value()) { | ||
| 251 | + stats_field_array_.emplace( | ||
| 252 | + env()->isolate(), | ||
| 253 | + static_cast<size_t>(FsStatsOffset::kFsStatsFieldsNumber)); | ||
| 254 | + } | ||
| 255 | + FillStatsArray(&stats_field_array_.value(), stat); | ||
| 256 | + Resolve(stats_field_array_->GetJSArray()); | ||
| 258 | 257 | } | |
| 259 | 258 | ||
| 260 | 259 | template <typename AliasedBufferT> | |
| 261 | 260 | void FSReqPromise<AliasedBufferT>::ResolveStatFs(const uv_statfs_t* stat) { | |
| 262 | - FillStatFsArray(&statfs_field_array_, stat); | ||
| 263 | - Resolve(statfs_field_array_.GetJSArray()); | ||
| 261 | + if (!statfs_field_array_.has_value()) { | ||
| 262 | + statfs_field_array_.emplace( | ||
| 263 | + env()->isolate(), | ||
| 264 | + static_cast<size_t>(FsStatFsOffset::kFsStatFsFieldsNumber)); | ||
| 265 | + } | ||
| 266 | + FillStatFsArray(&statfs_field_array_.value(), stat); | ||
| 267 | + Resolve(statfs_field_array_->GetJSArray()); | ||
| 264 | 268 | } | |
| 265 | 269 | ||
| 266 | 270 | template <typename AliasedBufferT> | |
@@ -280,8 +284,12 @@ void FSReqPromise<AliasedBufferT>::SetReturnValue( | |||
| 280 | 284 | template <typename AliasedBufferT> | |
| 281 | 285 | void FSReqPromise<AliasedBufferT>::MemoryInfo(MemoryTracker* tracker) const { | |
| 282 | 286 | FSReqBase::MemoryInfo(tracker); | |
| 283 | - tracker->TrackField("stats_field_array", stats_field_array_); | ||
| 284 | - tracker->TrackField("statfs_field_array", statfs_field_array_); | ||
| 287 | + if (stats_field_array_.has_value()) { | ||
| 288 | + tracker->TrackField("stats_field_array", stats_field_array_.value()); | ||
| 289 | + } | ||
| 290 | + if (statfs_field_array_.has_value()) { | ||
| 291 | + tracker->TrackField("statfs_field_array", statfs_field_array_.value()); | ||
| 292 | + } | ||
| 285 | 293 | } | |
| 286 | 294 | ||
| 287 | 295 | FSReqBase* GetReqWrap(const v8::FunctionCallbackInfo<v8::Value>& args, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -266,8 +266,11 @@ class FSReqPromise final : public FSReqBase { | |||
| 266 | 266 | bool use_bigint); | |
| 267 | 267 | ||
| 268 | 268 | bool finished_ = false; | |
| 269 | - AliasedBufferT stats_field_array_; | ||
| 270 | - AliasedBufferT statfs_field_array_; | ||
| 269 | + // Constructed lazily in ResolveStat()/ResolveStatFs(): most operations | ||
| 270 | + // never resolve with stats, and eagerly allocating the backing stores | ||
| 271 | + // for every request is a significant per-request cost. | ||
| 272 | + std::optional<AliasedBufferT> stats_field_array_; | ||
| 273 | + std::optional<AliasedBufferT> statfs_field_array_; | ||
| 271 | 274 | }; | |
| 272 | 275 | ||
| 273 | 276 | class FSReqAfterScope final { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,7 @@ fs.stat(__filename); | |||
| 20 | 20 | validateByRetainingPathFromNodes(nodes, 'Node / FSReqPromise', [ | |
| 21 | 21 | { node_name: 'FSReqPromise', edge_name: 'native_to_javascript' }, | |
| 22 | 22 | ]); | |
| 23 | - validateByRetainingPathFromNodes(nodes, 'Node / FSReqPromise', [ | ||
| 24 | - { node_name: 'Node / AliasedFloat64Array', edge_name: 'stats_field_array' }, | ||
| 25 | - ]); | ||
| 23 | + // The stats field array is allocated lazily when the request resolves | ||
| 24 | + // with stats, so it is not retained by a request that is still pending | ||
| 25 | + // and cannot be observed in a heap snapshot. | ||
| 26 | 26 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments