Skip to content
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

Replace scanner-based smap + annotations parsing with hand-crafted parsers #7923

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

MattAlp
Copy link
Contributor

@MattAlp MattAlp commented Nov 8, 2024

What Does This Do

Replaces the scanner-and-matcher-based NMT map annotation + /proc/smaps parsing with handcrafted parsers instead.

Motivation

The usage of Pattern, Matcher, and Scanner by the smap JFR events allocates and reserves a certain amount of baseline memory that has been flagged by customers. This replaces that to use a minimal amount of regex and eliminate the heaviest allocations.

Additional Notes

See PROF-10699 for an example of 'significant' memory usage.

Contributor Checklist

Jira ticket: PROF-10699

@MattAlp MattAlp requested a review from a team as a code owner November 8, 2024 16:13
Comment on lines 197 to 200
while (chars[i] != '-') {
buffer.append(chars[i]);
i++;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - I wonder how this compares to indexOf() + substring()
But no need to change this for now - probably the perf diff won't be dramatic

…/main/java/com/datadog/profiling/controller/openjdk/events/SmapEntryFactory.java

Co-authored-by: Jaroslav Bachorik <[email protected]>
Copy link
Contributor

@jbachorik jbachorik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that removing the complexity of reading the hexa numbers char-by-char just to have them parsed back to numeric values can be avoided by computing the number on the fly. That will simplify the code and reduce string operations.

@pr-commenter
Copy link

pr-commenter bot commented Nov 8, 2024

Benchmarks

Startup

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master mattalp/handcrafted-smap-parser
git_commit_date 1738333475 1738353513
git_commit_sha 8d0bb34 3b9b4d9
release_version 1.47.0-SNAPSHOT~8d0bb34e88 1.44.0-SNAPSHOT~3b9b4d967b
See matching parameters
Baseline Candidate
application insecure-bank insecure-bank
ci_job_date 1738357970 1738357970
ci_job_id 790014155 790014155
ci_pipeline_id 54626167 54626167
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
kernel_version Linux runner-zwes66s-project-304-concurrent-0-s9hnp6gq 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:50:46 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zwes66s-project-304-concurrent-0-s9hnp6gq 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:50:46 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
module Agent Agent
parent None None
variant iast iast

Summary

Found 12 performance improvements and 16 performance regressions! Performance is the same for 23 metrics, 12 unstable metrics.

scenario Δ mean execution_time candidate mean execution_time baseline mean execution_time
scenario:startup:insecure-bank:iast:Agent.start worse
[+26.563ms; +60.610ms] or [+2.253%; +5.140%]
1.223s 1.179s
scenario:startup:insecure-bank:iast:GlobalTracer worse
[+72.407ms; +77.238ms] or [+31.201%; +33.283%]
306.885ms 232.063ms
scenario:startup:insecure-bank:iast:Telemetry better
[-1.548ms; -1.039ms] or [-17.372%; -11.661%]
7.617ms 8.911ms
scenario:startup:insecure-bank:iast_HARDCODED_SECRET_DISABLED:Agent.start worse
[+49.181ms; +57.339ms] or [+4.212%; +4.911%]
1.221s 1.168s
scenario:startup:insecure-bank:iast_HARDCODED_SECRET_DISABLED:GlobalTracer worse
[+73.531ms; +75.672ms] or [+31.840%; +32.767%]
305.541ms 230.939ms
scenario:startup:insecure-bank:iast_HARDCODED_SECRET_DISABLED:Telemetry better
[-1.213ms; -0.968ms] or [-14.100%; -11.246%]
7.514ms 8.604ms
scenario:startup:insecure-bank:iast_TELEMETRY_OFF:Agent.start worse
[+53.839ms; +60.736ms] or [+4.632%; +5.225%]
1.220s 1.162s
scenario:startup:insecure-bank:iast_TELEMETRY_OFF:GlobalTracer worse
[+74.889ms; +76.627ms] or [+32.503%; +33.258%]
306.163ms 230.405ms
scenario:startup:insecure-bank:iast_TELEMETRY_OFF:Remote Config worse
[+13.841µs; +43.095µs] or [+2.296%; +7.147%]
631.419µs 602.951µs
scenario:startup:insecure-bank:iast_TELEMETRY_OFF:Telemetry better
[-1.166ms; -0.858ms] or [-13.641%; -10.035%]
7.537ms 8.549ms
scenario:startup:insecure-bank:tracing:Agent.start worse
[+44.160ms; +73.659ms] or [+4.249%; +7.087%]
1.098s 1.039s
scenario:startup:insecure-bank:tracing:GlobalTracer worse
[+73.129ms; +81.378ms] or [+30.340%; +33.762%]
318.287ms 241.033ms
scenario:startup:petclinic:appsec:Agent.start worse
[+32.487ms; +52.275ms] or [+2.748%; +4.421%]
1.225s 1.182s
scenario:startup:petclinic:appsec:BytebuddyAgent better
[-28.031ms; -16.972ms] or [-3.820%; -2.313%]
711.293ms 733.795ms
scenario:startup:petclinic:appsec:GlobalTracer worse
[+72.976ms; +78.866ms] or [+30.707%; +33.186%]
313.572ms 237.651ms
scenario:startup:petclinic:appsec:IAST better
[-2.909ms; -1.787ms] or [-13.414%; -8.240%]
19.338ms 21.686ms
scenario:startup:petclinic:appsec:AppSec better
[-10.273ms; -6.534ms] or [-5.840%; -3.714%]
167.507ms 175.911ms
scenario:startup:petclinic:iast:GlobalTracer worse
[+70.832ms; +75.346ms] or [+30.362%; +32.297%]
306.380ms 233.291ms
scenario:startup:petclinic:iast:Telemetry better
[-1.660ms; -1.055ms] or [-18.595%; -11.823%]
7.568ms 8.925ms
scenario:startup:petclinic:profiling:Agent.start worse
[+53.373ms; +61.371ms] or [+4.235%; +4.869%]
1.318s 1.260s
scenario:startup:petclinic:profiling:BytebuddyAgent better
[-18.724ms; -14.553ms] or [-2.650%; -2.060%]
689.955ms 706.593ms
scenario:startup:petclinic:profiling:GlobalTracer worse
[+78.923ms; +83.583ms] or [+22.453%; +23.779%]
432.758ms 351.505ms
scenario:startup:petclinic:profiling:Remote Config better
[-62.609µs; -24.799µs] or [-8.862%; -3.510%]
662.814µs 706.518µs
scenario:startup:petclinic:profiling:Telemetry better
[-1.374ms; -1.124ms] or [-15.376%; -12.583%]
7.684ms 8.933ms
scenario:startup:petclinic:tracing:Agent.start worse
[+54.224ms; +62.461ms] or [+5.239%; +6.035%]
1.093s 1.035s
scenario:startup:petclinic:tracing:BytebuddyAgent better
[-20.254ms; -15.652ms] or [-2.837%; -2.193%]
695.886ms 713.839ms
scenario:startup:petclinic:tracing:GlobalTracer worse
[+76.837ms; +79.025ms] or [+32.088%; +33.001%]
317.392ms 239.461ms
scenario:startup:petclinic:tracing:Remote Config better
[-43.761µs; -15.370µs] or [-6.142%; -2.157%]
682.873µs 712.438µs
Startup time reports for petclinic
gantt
    title petclinic - global startup overhead: candidate=1.44.0-SNAPSHOT~3b9b4d967b, baseline=1.47.0-SNAPSHOT~8d0bb34e88

    dateFormat X
    axisFormat %s
section tracing
Agent [baseline] (1.035 s) : 0, 1034963
Total [baseline] (10.462 s) : 0, 10462175
Agent [candidate] (1.093 s) : 0, 1093305
Total [candidate] (10.455 s) : 0, 10454972
section appsec
Agent [baseline] (1.182 s) : 0, 1182360
Total [baseline] (10.764 s) : 0, 10764101
Agent [candidate] (1.225 s) : 0, 1224742
Total [candidate] (10.761 s) : 0, 10761430
section iast
Agent [baseline] (1.182 s) : 0, 1181698
Total [baseline] (11.055 s) : 0, 11054547
Agent [candidate] (1.223 s) : 0, 1222506
Total [candidate] (10.97 s) : 0, 10969706
section profiling
Agent [baseline] (1.26 s) : 0, 1260394
Total [baseline] (10.861 s) : 0, 10860961
Agent [candidate] (1.318 s) : 0, 1317766
Total [candidate] (10.839 s) : 0, 10839264
Loading
  • baseline results
Module Variant Duration Δ tracing
Agent tracing 1.035 s -
Agent appsec 1.182 s 147.397 ms (14.2%)
Agent iast 1.182 s 146.735 ms (14.2%)
Agent profiling 1.26 s 225.431 ms (21.8%)
Total tracing 10.462 s -
Total appsec 10.764 s 301.926 ms (2.9%)
Total iast 11.055 s 592.373 ms (5.7%)
Total profiling 10.861 s 398.786 ms (3.8%)
  • candidate results
Module Variant Duration Δ tracing
Agent tracing 1.093 s -
Agent appsec 1.225 s 131.436 ms (12.0%)
Agent iast 1.223 s 129.201 ms (11.8%)
Agent profiling 1.318 s 224.461 ms (20.5%)
Total tracing 10.455 s -
Total appsec 10.761 s 306.457 ms (2.9%)
Total iast 10.97 s 514.733 ms (4.9%)
Total profiling 10.839 s 384.291 ms (3.7%)
gantt
    title petclinic - break down per module: candidate=1.44.0-SNAPSHOT~3b9b4d967b, baseline=1.47.0-SNAPSHOT~8d0bb34e88

    dateFormat X
    axisFormat %s
section tracing
BytebuddyAgent [baseline] (713.839 ms) : 0, 713839
BytebuddyAgent [candidate] (695.886 ms) : 0, 695886
GlobalTracer [baseline] (239.461 ms) : 0, 239461
GlobalTracer [candidate] (317.392 ms) : 0, 317392
AppSec [baseline] (55.101 ms) : 0, 55101
AppSec [candidate] (54.901 ms) : 0, 54901
Remote Config [baseline] (712.438 µs) : 0, 712
Remote Config [candidate] (682.873 µs) : 0, 683
Telemetry [baseline] (10.678 ms) : 0, 10678
Telemetry [candidate] (10.686 ms) : 0, 10686
section appsec
BytebuddyAgent [baseline] (733.795 ms) : 0, 733795
BytebuddyAgent [candidate] (711.293 ms) : 0, 711293
GlobalTracer [baseline] (237.651 ms) : 0, 237651
GlobalTracer [candidate] (313.572 ms) : 0, 313572
AppSec [baseline] (175.911 ms) : 0, 175911
AppSec [candidate] (167.507 ms) : 0, 167507
IAST [baseline] (21.686 ms) : 0, 21686
IAST [candidate] (19.338 ms) : 0, 19338
Remote Config [baseline] (652.388 µs) : 0, 652
Remote Config [candidate] (655.626 µs) : 0, 656
Telemetry [baseline] (8.318 ms) : 0, 8318
Telemetry [candidate] (8.273 ms) : 0, 8273
section iast
BytebuddyAgent [baseline] (842.802 ms) : 0, 842802
BytebuddyAgent [candidate] (815.079 ms) : 0, 815079
GlobalTracer [baseline] (233.291 ms) : 0, 233291
GlobalTracer [candidate] (306.38 ms) : 0, 306380
AppSec [baseline] (55.323 ms) : 0, 55323
AppSec [candidate] (57.152 ms) : 0, 57152
IAST [baseline] (25.286 ms) : 0, 25286
IAST [candidate] (21.91 ms) : 0, 21910
Remote Config [baseline] (648.064 µs) : 0, 648
Remote Config [candidate] (632.822 µs) : 0, 633
Telemetry [baseline] (8.925 ms) : 0, 8925
Telemetry [candidate] (7.568 ms) : 0, 7568
section profiling
BytebuddyAgent [baseline] (706.593 ms) : 0, 706593
BytebuddyAgent [candidate] (689.955 ms) : 0, 689955
GlobalTracer [baseline] (351.505 ms) : 0, 351505
GlobalTracer [candidate] (432.758 ms) : 0, 432758
AppSec [baseline] (55.236 ms) : 0, 55236
AppSec [candidate] (53.541 ms) : 0, 53541
Remote Config [baseline] (706.518 µs) : 0, 707
Remote Config [candidate] (662.814 µs) : 0, 663
Telemetry [baseline] (8.933 ms) : 0, 8933
Telemetry [candidate] (7.684 ms) : 0, 7684
ProfilingAgent [baseline] (95.073 ms) : 0, 95073
ProfilingAgent [candidate] (93.946 ms) : 0, 93946
Profiling [baseline] (95.097 ms) : 0, 95097
Profiling [candidate] (93.971 ms) : 0, 93971
Loading
Startup time reports for insecure-bank
gantt
    title insecure-bank - global startup overhead: candidate=1.44.0-SNAPSHOT~3b9b4d967b, baseline=1.47.0-SNAPSHOT~8d0bb34e88

    dateFormat X
    axisFormat %s
section tracing
Agent [baseline] (1.039 s) : 0, 1039301
Total [baseline] (8.634 s) : 0, 8634447
Agent [candidate] (1.098 s) : 0, 1098211
Total [candidate] (8.667 s) : 0, 8667465
section iast
Agent [baseline] (1.179 s) : 0, 1179120
Total [baseline] (9.221 s) : 0, 9221205
Agent [candidate] (1.223 s) : 0, 1222707
Total [candidate] (9.25 s) : 0, 9250034
section iast_HARDCODED_SECRET_DISABLED
Agent [baseline] (1.168 s) : 0, 1167582
Total [baseline] (9.171 s) : 0, 9170708
Agent [candidate] (1.221 s) : 0, 1220843
Total [candidate] (9.176 s) : 0, 9175992
section iast_TELEMETRY_OFF
Agent [baseline] (1.162 s) : 0, 1162424
Total [baseline] (9.202 s) : 0, 9201505
Agent [candidate] (1.22 s) : 0, 1219712
Total [candidate] (9.203 s) : 0, 9203055
Loading
  • baseline results
Module Variant Duration Δ tracing
Agent tracing 1.039 s -
Agent iast 1.179 s 139.819 ms (13.5%)
Agent iast_HARDCODED_SECRET_DISABLED 1.168 s 128.281 ms (12.3%)
Agent iast_TELEMETRY_OFF 1.162 s 123.124 ms (11.8%)
Total tracing 8.634 s -
Total iast 9.221 s 586.759 ms (6.8%)
Total iast_HARDCODED_SECRET_DISABLED 9.171 s 536.262 ms (6.2%)
Total iast_TELEMETRY_OFF 9.202 s 567.058 ms (6.6%)
  • candidate results
Module Variant Duration Δ tracing
Agent tracing 1.098 s -
Agent iast 1.223 s 124.496 ms (11.3%)
Agent iast_HARDCODED_SECRET_DISABLED 1.221 s 122.632 ms (11.2%)
Agent iast_TELEMETRY_OFF 1.22 s 121.501 ms (11.1%)
Total tracing 8.667 s -
Total iast 9.25 s 582.569 ms (6.7%)
Total iast_HARDCODED_SECRET_DISABLED 9.176 s 508.527 ms (5.9%)
Total iast_TELEMETRY_OFF 9.203 s 535.59 ms (6.2%)
gantt
    title insecure-bank - break down per module: candidate=1.44.0-SNAPSHOT~3b9b4d967b, baseline=1.47.0-SNAPSHOT~8d0bb34e88

    dateFormat X
    axisFormat %s
section tracing
BytebuddyAgent [baseline] (715.265 ms) : 0, 715265
BytebuddyAgent [candidate] (699.557 ms) : 0, 699557
GlobalTracer [baseline] (241.033 ms) : 0, 241033
GlobalTracer [candidate] (318.287 ms) : 0, 318287
AppSec [baseline] (55.544 ms) : 0, 55544
AppSec [candidate] (55.179 ms) : 0, 55179
Remote Config [baseline] (713.537 µs) : 0, 714
Remote Config [candidate] (697.109 µs) : 0, 697
Telemetry [baseline] (11.565 ms) : 0, 11565
Telemetry [candidate] (10.655 ms) : 0, 10655
section iast
BytebuddyAgent [baseline] (841.632 ms) : 0, 841632
BytebuddyAgent [candidate] (814.463 ms) : 0, 814463
GlobalTracer [baseline] (232.063 ms) : 0, 232063
GlobalTracer [candidate] (306.885 ms) : 0, 306885
AppSec [baseline] (54.512 ms) : 0, 54512
AppSec [candidate] (58.346 ms) : 0, 58346
IAST [baseline] (26.076 ms) : 0, 26076
IAST [candidate] (20.964 ms) : 0, 20964
Remote Config [baseline] (633.683 µs) : 0, 634
Remote Config [candidate] (632.475 µs) : 0, 632
Telemetry [baseline] (8.911 ms) : 0, 8911
Telemetry [candidate] (7.617 ms) : 0, 7617
section iast_HARDCODED_SECRET_DISABLED
BytebuddyAgent [baseline] (832.575 ms) : 0, 832575
BytebuddyAgent [candidate] (813.856 ms) : 0, 813856
GlobalTracer [baseline] (230.939 ms) : 0, 230939
GlobalTracer [candidate] (305.541 ms) : 0, 305541
AppSec [baseline] (53.174 ms) : 0, 53174
AppSec [candidate] (56.769 ms) : 0, 56769
IAST [baseline] (26.428 ms) : 0, 26428
IAST [candidate] (22.728 ms) : 0, 22728
Remote Config [baseline] (620.112 µs) : 0, 620
Remote Config [candidate] (627.241 µs) : 0, 627
Telemetry [baseline] (8.604 ms) : 0, 8604
Telemetry [candidate] (7.514 ms) : 0, 7514
section iast_TELEMETRY_OFF
BytebuddyAgent [baseline] (829.288 ms) : 0, 829288
BytebuddyAgent [candidate] (812.63 ms) : 0, 812630
GlobalTracer [baseline] (230.405 ms) : 0, 230405
GlobalTracer [candidate] (306.163 ms) : 0, 306163
AppSec [baseline] (53.378 ms) : 0, 53378
AppSec [candidate] (57.46 ms) : 0, 57460
IAST [baseline] (24.96 ms) : 0, 24960
IAST [candidate] (21.483 ms) : 0, 21483
Remote Config [baseline] (602.951 µs) : 0, 603
Remote Config [candidate] (631.419 µs) : 0, 631
Telemetry [baseline] (8.549 ms) : 0, 8549
Telemetry [candidate] (7.537 ms) : 0, 7537
Loading

Load

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
end_time 2025-01-31T20:42:50 2025-01-31T20:49:52
git_branch master mattalp/handcrafted-smap-parser
git_commit_date 1738333475 1738353513
git_commit_sha 8d0bb34 3b9b4d9
release_version 1.47.0-SNAPSHOT~8d0bb34e88 1.44.0-SNAPSHOT~3b9b4d967b
start_time 2025-01-31T20:42:36 2025-01-31T20:49:39
See matching parameters
Baseline Candidate
application insecure-bank insecure-bank
ci_job_date 1738356946 1738356946
ci_job_id 790014156 790014156
ci_pipeline_id 54626167 54626167
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
kernel_version Linux runner-a4w3ykiz-project-304-concurrent-0-pcp8ay45 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:50:46 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux Linux runner-a4w3ykiz-project-304-concurrent-0-pcp8ay45 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:50:46 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
variant iast iast

Summary

Found 1 performance improvements and 0 performance regressions! Performance is the same for 11 metrics, 16 unstable metrics.

scenario Δ mean http_req_duration Δ mean throughput candidate mean http_req_duration candidate mean throughput baseline mean http_req_duration baseline mean throughput
scenario:load:insecure-bank:iast_FULL better
[-106.242µs; -59.495µs] or [-14.441%; -8.087%]
unstable
[-596.808op/s; +1930.141op/s] or [-9.947%; +32.169%]
652.824µs 6666.667op/s 735.693µs 6000.000op/s
Request duration reports for petclinic
gantt
    title petclinic - request duration [CI 0.99] : candidate=1.44.0-SNAPSHOT~3b9b4d967b, baseline=1.47.0-SNAPSHOT~8d0bb34e88
    dateFormat X
    axisFormat %s
section baseline
no_agent (1.359 ms) : 1340, 1378
.   : milestone, 1359,
appsec (1.748 ms) : 1724, 1771
.   : milestone, 1748,
appsec_no_iast (1.759 ms) : 1735, 1782
.   : milestone, 1759,
iast (1.519 ms) : 1496, 1543
.   : milestone, 1519,
profiling (1.495 ms) : 1471, 1519
.   : milestone, 1495,
tracing (1.485 ms) : 1461, 1509
.   : milestone, 1485,
section candidate
no_agent (1.353 ms) : 1333, 1372
.   : milestone, 1353,
appsec (1.746 ms) : 1722, 1770
.   : milestone, 1746,
appsec_no_iast (1.76 ms) : 1736, 1785
.   : milestone, 1760,
iast (1.505 ms) : 1483, 1528
.   : milestone, 1505,
profiling (1.495 ms) : 1471, 1518
.   : milestone, 1495,
tracing (1.499 ms) : 1474, 1523
.   : milestone, 1499,
Loading
  • baseline results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 1.359 ms [1.34 ms, 1.378 ms] -
appsec 1.748 ms [1.724 ms, 1.771 ms] 388.678 µs (28.6%)
appsec_no_iast 1.759 ms [1.735 ms, 1.782 ms] 399.585 µs (29.4%)
iast 1.519 ms [1.496 ms, 1.543 ms] 160.347 µs (11.8%)
profiling 1.495 ms [1.471 ms, 1.519 ms] 135.509 µs (10.0%)
tracing 1.485 ms [1.461 ms, 1.509 ms] 125.983 µs (9.3%)
  • candidate results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 1.353 ms [1.333 ms, 1.372 ms] -
appsec 1.746 ms [1.722 ms, 1.77 ms] 393.273 µs (29.1%)
appsec_no_iast 1.76 ms [1.736 ms, 1.785 ms] 407.39 µs (30.1%)
iast 1.505 ms [1.483 ms, 1.528 ms] 152.594 µs (11.3%)
profiling 1.495 ms [1.471 ms, 1.518 ms] 141.922 µs (10.5%)
tracing 1.499 ms [1.474 ms, 1.523 ms] 145.662 µs (10.8%)
Request duration reports for insecure-bank
gantt
    title insecure-bank - request duration [CI 0.99] : candidate=1.44.0-SNAPSHOT~3b9b4d967b, baseline=1.47.0-SNAPSHOT~8d0bb34e88
    dateFormat X
    axisFormat %s
section baseline
no_agent (375.389 µs) : 353, 397
.   : milestone, 375,
iast (516.495 µs) : 493, 540
.   : milestone, 516,
iast_FULL (735.693 µs) : 714, 758
.   : milestone, 736,
iast_GLOBAL (553.606 µs) : 532, 575
.   : milestone, 554,
iast_HARDCODED_SECRET_DISABLED (511.885 µs) : 489, 535
.   : milestone, 512,
iast_INACTIVE (464.2 µs) : 442, 486
.   : milestone, 464,
iast_TELEMETRY_OFF (491.902 µs) : 469, 515
.   : milestone, 492,
tracing (459.536 µs) : 438, 481
.   : milestone, 460,
section candidate
no_agent (378.697 µs) : 359, 398
.   : milestone, 379,
iast (492.76 µs) : 471, 514
.   : milestone, 493,
iast_FULL (652.824 µs) : 631, 674
.   : milestone, 653,
iast_GLOBAL (521.981 µs) : 499, 544
.   : milestone, 522,
iast_HARDCODED_SECRET_DISABLED (494.857 µs) : 473, 516
.   : milestone, 495,
iast_INACTIVE (453.027 µs) : 432, 474
.   : milestone, 453,
iast_TELEMETRY_OFF (490.745 µs) : 468, 513
.   : milestone, 491,
tracing (452.768 µs) : 432, 474
.   : milestone, 453,
Loading
  • baseline results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 375.389 µs [353.327 µs, 397.45 µs] -
iast 516.495 µs [492.772 µs, 540.218 µs] 141.106 µs (37.6%)
iast_FULL 735.693 µs [713.852 µs, 757.533 µs] 360.304 µs (96.0%)
iast_GLOBAL 553.606 µs [531.745 µs, 575.468 µs] 178.218 µs (47.5%)
iast_HARDCODED_SECRET_DISABLED 511.885 µs [488.602 µs, 535.169 µs] 136.497 µs (36.4%)
iast_INACTIVE 464.2 µs [442.488 µs, 485.911 µs] 88.811 µs (23.7%)
iast_TELEMETRY_OFF 491.902 µs [468.722 µs, 515.083 µs] 116.513 µs (31.0%)
tracing 459.536 µs [437.936 µs, 481.137 µs] 84.147 µs (22.4%)
  • candidate results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 378.697 µs [358.995 µs, 398.399 µs] -
iast 492.76 µs [471.492 µs, 514.028 µs] 114.063 µs (30.1%)
iast_FULL 652.824 µs [631.224 µs, 674.424 µs] 274.127 µs (72.4%)
iast_GLOBAL 521.981 µs [499.497 µs, 544.466 µs] 143.284 µs (37.8%)
iast_HARDCODED_SECRET_DISABLED 494.857 µs [473.426 µs, 516.287 µs] 116.16 µs (30.7%)
iast_INACTIVE 453.027 µs [431.949 µs, 474.106 µs] 74.33 µs (19.6%)
iast_TELEMETRY_OFF 490.745 µs [468.471 µs, 513.02 µs] 112.048 µs (29.6%)
tracing 452.768 µs [431.643 µs, 473.894 µs] 74.071 µs (19.6%)

Dacapo

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master mattalp/handcrafted-smap-parser
git_commit_date 1738333475 1738353513
git_commit_sha 8d0bb34 3b9b4d9
release_version 1.47.0-SNAPSHOT~8d0bb34e88 1.44.0-SNAPSHOT~3b9b4d967b
See matching parameters
Baseline Candidate
application biojava biojava
ci_job_date 1738357469 1738357469
ci_job_id 790014157 790014157
ci_pipeline_id 54626167 54626167
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
kernel_version Linux runner-zwes66s-project-304-concurrent-1-jxi3jb0d 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:50:46 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zwes66s-project-304-concurrent-1-jxi3jb0d 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:50:46 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
variant appsec appsec

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 12 metrics, 0 unstable metrics.

Execution time for biojava
gantt
    title biojava - execution time [CI 0.99] : candidate=1.44.0-SNAPSHOT~3b9b4d967b, baseline=1.47.0-SNAPSHOT~8d0bb34e88
    dateFormat X
    axisFormat %s
section baseline
no_agent (15.259 s) : 15259000, 15259000
.   : milestone, 15259000,
appsec (14.901 s) : 14901000, 14901000
.   : milestone, 14901000,
iast (18.861 s) : 18861000, 18861000
.   : milestone, 18861000,
iast_GLOBAL (18.033 s) : 18033000, 18033000
.   : milestone, 18033000,
profiling (15.066 s) : 15066000, 15066000
.   : milestone, 15066000,
tracing (14.811 s) : 14811000, 14811000
.   : milestone, 14811000,
section candidate
no_agent (15.526 s) : 15526000, 15526000
.   : milestone, 15526000,
appsec (15.036 s) : 15036000, 15036000
.   : milestone, 15036000,
iast (18.658 s) : 18658000, 18658000
.   : milestone, 18658000,
iast_GLOBAL (17.854 s) : 17854000, 17854000
.   : milestone, 17854000,
profiling (14.989 s) : 14989000, 14989000
.   : milestone, 14989000,
tracing (14.946 s) : 14946000, 14946000
.   : milestone, 14946000,
Loading
  • baseline results
Variant Execution Time [CI 0.99] Δ no_agent
no_agent 15.259 s [15.259 s, 15.259 s] -
appsec 14.901 s [14.901 s, 14.901 s] -358.0 ms (-2.3%)
iast 18.861 s [18.861 s, 18.861 s] 3.602 s (23.6%)
iast_GLOBAL 18.033 s [18.033 s, 18.033 s] 2.774 s (18.2%)
profiling 15.066 s [15.066 s, 15.066 s] -193.0 ms (-1.3%)
tracing 14.811 s [14.811 s, 14.811 s] -448.0 ms (-2.9%)
  • candidate results
Variant Execution Time [CI 0.99] Δ no_agent
no_agent 15.526 s [15.526 s, 15.526 s] -
appsec 15.036 s [15.036 s, 15.036 s] -490.0 ms (-3.2%)
iast 18.658 s [18.658 s, 18.658 s] 3.132 s (20.2%)
iast_GLOBAL 17.854 s [17.854 s, 17.854 s] 2.328 s (15.0%)
profiling 14.989 s [14.989 s, 14.989 s] -537.0 ms (-3.5%)
tracing 14.946 s [14.946 s, 14.946 s] -580.0 ms (-3.7%)
Execution time for tomcat
gantt
    title tomcat - execution time [CI 0.99] : candidate=1.44.0-SNAPSHOT~3b9b4d967b, baseline=1.47.0-SNAPSHOT~8d0bb34e88
    dateFormat X
    axisFormat %s
section baseline
no_agent (1.472 ms) : 1460, 1483
.   : milestone, 1472,
appsec (2.362 ms) : 2319, 2406
.   : milestone, 2362,
iast (2.101 ms) : 2047, 2156
.   : milestone, 2101,
iast_GLOBAL (2.152 ms) : 2097, 2207
.   : milestone, 2152,
profiling (1.982 ms) : 1937, 2026
.   : milestone, 1982,
tracing (1.95 ms) : 1908, 1992
.   : milestone, 1950,
section candidate
no_agent (1.47 ms) : 1458, 1481
.   : milestone, 1470,
appsec (2.345 ms) : 2303, 2387
.   : milestone, 2345,
iast (2.086 ms) : 2033, 2138
.   : milestone, 2086,
iast_GLOBAL (2.129 ms) : 2076, 2183
.   : milestone, 2129,
profiling (1.959 ms) : 1917, 2002
.   : milestone, 1959,
tracing (1.932 ms) : 1891, 1973
.   : milestone, 1932,
Loading
  • baseline results
Variant Execution Time [CI 0.99] Δ no_agent
no_agent 1.472 ms [1.46 ms, 1.483 ms] -
appsec 2.362 ms [2.319 ms, 2.406 ms] 890.654 µs (60.5%)
iast 2.101 ms [2.047 ms, 2.156 ms] 629.418 µs (42.8%)
iast_GLOBAL 2.152 ms [2.097 ms, 2.207 ms] 680.704 µs (46.3%)
profiling 1.982 ms [1.937 ms, 2.026 ms] 509.836 µs (34.6%)
tracing 1.95 ms [1.908 ms, 1.992 ms] 478.263 µs (32.5%)
  • candidate results
Variant Execution Time [CI 0.99] Δ no_agent
no_agent 1.47 ms [1.458 ms, 1.481 ms] -
appsec 2.345 ms [2.303 ms, 2.387 ms] 875.201 µs (59.5%)
iast 2.086 ms [2.033 ms, 2.138 ms] 615.988 µs (41.9%)
iast_GLOBAL 2.129 ms [2.076 ms, 2.183 ms] 659.502 µs (44.9%)
profiling 1.959 ms [1.917 ms, 2.002 ms] 489.365 µs (33.3%)
tracing 1.932 ms [1.891 ms, 1.973 ms] 462.145 µs (31.4%)

@jbachorik
Copy link
Contributor

Any progress on this?

@MattAlp MattAlp requested a review from jbachorik November 19, 2024 23:34
MattAlp and others added 2 commits November 19, 2024 18:34
…/main/java/com/datadog/profiling/controller/openjdk/events/SmapEntryFactory.java

Co-authored-by: datadog-datadog-prod-us1[bot] <88084959+datadog-datadog-prod-us1[bot]@users.noreply.github.com>
System.out.println("ATTR: " + attributeName);
switch (attributeName) {
case "Size":
size = Long.decode(buffer.toString()) * 1024;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this is still using string->stringBuffer->number conversion.
I would propose extracting the logic from parseLine method for converting the stream of characters into a number.

Something like:

long readLong(String line, int from, char delimiter, int base) throws IndexOutOfBoundsException {
  long number = 0;
  for (int i = from; i < line.length() && (char c = line.charAt(i)) != delimiter; i++) {
    number *= base;
    number += Character.digit(char, base);
  }
  return number;
}

With this you should also unify the approach for reading the char at i-th position. Currently, one method is using charAt(i) while the other first converts the line into char array and then accesses that array elements.
I have no strong preference for one or the other - it would just be nice to keep to the same convention :)

Copy link
Contributor Author

@MattAlp MattAlp Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept this section as-is because I expect the header parsing to remain stable while the KV pairs may change in format, hence the approach of loading the value into the buffer & then parsing it wholesale (with different rules depending on the attribute). Of course, this could be moved into the switch itself. Additionally, decode and parseLong won't come with the overhead of the original Scanner-based implementation.

As for the digit parsing, I agree that it could be extracted with 2 caveats:

  1. We would have to also return the offset into the line after reading in order to continue the parsing, which means a new (data) class to return this tuple.
  2. Building off of 1, I prefer to keep the indirection to a minimum here to explicitly spell out the parsing for this bespoke format (or to use easily-understood stdlib features such as Scanner, which isn't viable for low-memory JVMs, leading to the Boxed.parseBoxed / decode usage seen here)

We could also swap out the String for ByteBuffer as you've mentioned earlier, and that should get us position tracking "for free". WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try with ByteBuffer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, this will minimize whatever minimal GC churn / extra heap allocations that come from this.

@MattAlp MattAlp force-pushed the mattalp/handcrafted-smap-parser branch from 11c7ea0 to d576a02 Compare December 5, 2024 21:06
@MattAlp MattAlp marked this pull request as draft January 31, 2025 20:31
@@ -350,6 +440,7 @@ static List<? extends Event> collectEvents() {
} catch (FileNotFoundException e) {
return List.of(new SmapParseErrorEvent(ErrorReason.SMAP_FILE_NOT_FOUND));
} catch (Exception e) {
e.printStackTrace();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

Avoid printStackTrace(); use a logger call instead. (...read more)

Use a logging framework instead of printStackTrace() when handling exceptions. printStackTrace() can be useful during development for quick debugging, but it is not suitable for production code.

View in Datadog  Leave us feedback  Documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants