Commit ef1310f
Vineeth Rao Kanaparthi
subscriber: skip RwLock in EnvFilter span callbacks when no dynamic directives
EnvFilter maintains `by_id: RwLock<HashMap<Id, SpanMatcher>>` and
`by_cs: RwLock<HashMap<Identifier, CallsiteMatcher>>` for tracking
per-span field-level match state. These maps are only populated when
`has_dynamics` is true (i.e., when the filter has span/field-level
directives like `my_crate[span_name]=debug`).
However, the span lifecycle callbacks (`on_new_span`, `on_enter`,
`on_exit`, `on_close`, `on_record`) unconditionally acquire the
`by_id` read lock (or write lock for `on_close`) on every call. When
`has_dynamics` is false — which is the common case for pure
target=level configurations like `RUST_LOG=info,hyper=warn` — these
maps are always empty, and the lock acquisition is wasted work.
Under high concurrency this becomes a bottleneck: a GDB backtrace of a
Tokio-based HTTP server under load showed ~25 worker threads contending
on these RwLock acquisitions, with threads in `read_contended` blocked
by `on_close`'s write lock. The contention scales with the number of
EnvFilter instances in the subscriber layer stack (one per layer when
using per-layer filtering).
This commit adds an early `if !self.has_dynamics { return; }` guard to
each of the five span lifecycle methods. This is a pure no-op when
dynamic directives are present (the existing code path runs unchanged),
and completely eliminates the lock traffic for the common static-only
configuration.1 parent efc690f commit ef1310f
File tree
2 files changed
+109
-0
lines changed- tracing-subscriber
- src/filter/env
- tests/env_filter
2 files changed
+109
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
566 | 566 | | |
567 | 567 | | |
568 | 568 | | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
569 | 572 | | |
570 | 573 | | |
571 | 574 | | |
| |||
579 | 582 | | |
580 | 583 | | |
581 | 584 | | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
582 | 588 | | |
583 | 589 | | |
584 | 590 | | |
| |||
593 | 599 | | |
594 | 600 | | |
595 | 601 | | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
596 | 605 | | |
597 | 606 | | |
598 | 607 | | |
| |||
604 | 613 | | |
605 | 614 | | |
606 | 615 | | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
607 | 619 | | |
608 | 620 | | |
609 | 621 | | |
| |||
620 | 632 | | |
621 | 633 | | |
622 | 634 | | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
623 | 638 | | |
624 | 639 | | |
625 | 640 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
0 commit comments