Skip to content

Add defensive ddcommon_ffi checks for Slice#604

Merged
morrisonlevi merged 6 commits into
mainfrom
levi/slice-ffi
Sep 6, 2024
Merged

Add defensive ddcommon_ffi checks for Slice#604
morrisonlevi merged 6 commits into
mainfrom
levi/slice-ffi

Conversation

@morrisonlevi
Copy link
Copy Markdown
Contributor

@morrisonlevi morrisonlevi commented Aug 29, 2024

What does this PR do?

Adds defensive checks in Slice in ddcommon_ffi and reroutes some code to use it.

Motivation

It seems it is prudent to add checks here. At some point you need to be able to trust the FFI caller to uphold needed invariants, but it's a bit too easy to zero-initialize stuff in C and not fix it up for these Slices.

Additional Notes

@AlexJF had some of their time wasted due to not early detecting this mistake..

How to test the change?

Regular testing is fine. This accepts more valid inputs, but if you had invalid inputs for some edge cases, it might crash now.
1 . If you provide a null pointer but non-zero length will now panic.
2. If you provide a pointer that is not aligned correctly for the slice type, it will now panic.

It seems it is prudent to add checks here. At some point you need to
be able to trust the FFI caller to uphold needed invariants, but it's
a bit too easy to zero-initialize stuff in C and not fix it up for
these Slices.
@morrisonlevi morrisonlevi requested a review from a team as a code owner August 29, 2024 22:53
@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented Aug 29, 2024

Benchmarks

Comparison

Benchmark execution time: 2024-09-06 22:04:50

Comparing candidate commit 63171ce in PR branch levi/slice-ffi with baseline commit cef5282 in branch main.

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

Candidate

Candidate benchmark details

Group 1

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 63171ce 1725659685 levi/slice-ffi
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
normalization/normalize_name/normalize_name/Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Lo... execution_time 299.387µs 302.783µs ± 0.901µs 302.958µs ± 0.517µs 303.401µs 303.777µs 303.993µs 304.116µs 0.38% -1.178 1.160 0.30% 0.064µs 1 200
normalization/normalize_name/normalize_name/Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Lo... throughput 3288214.810op/s 3302724.890op/s ± 9865.492op/s 3300783.377op/s ± 5621.118op/s 3306955.908op/s 3322198.517op/s 3329057.057op/s 3340163.110op/s 1.19% 1.194 1.214 0.30% 697.596op/s 1 200
normalization/normalize_name/normalize_name/bad-name execution_time 28.554µs 28.815µs ± 0.090µs 28.823µs ± 0.064µs 28.887µs 28.940µs 28.966µs 29.003µs 0.63% -0.539 -0.062 0.31% 0.006µs 1 200
normalization/normalize_name/normalize_name/bad-name throughput 34479422.647op/s 34703901.780op/s ± 108063.966op/s 34695081.602op/s ± 77276.455op/s 34773766.302op/s 34887431.215op/s 34993859.862op/s 35020839.099op/s 0.94% 0.555 -0.036 0.31% 7641.276op/s 1 200
normalization/normalize_name/normalize_name/good execution_time 16.526µs 16.687µs ± 0.095µs 16.739µs ± 0.049µs 16.772µs 16.790µs 16.824µs 16.949µs 1.25% -0.217 -1.375 0.57% 0.007µs 1 200
normalization/normalize_name/normalize_name/good throughput 59002211.566op/s 59930089.367op/s ± 342455.154op/s 59741386.754op/s ± 174219.165op/s 60286634.829op/s 60480038.411op/s 60503652.014op/s 60511215.441op/s 1.29% 0.227 -1.385 0.57% 24215.236op/s 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
normalization/normalize_name/normalize_name/Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Lo... execution_time [302.658µs; 302.908µs] or [-0.041%; +0.041%] None None None
normalization/normalize_name/normalize_name/Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Lo... throughput [3301357.627op/s; 3304092.152op/s] or [-0.041%; +0.041%] None None None
normalization/normalize_name/normalize_name/bad-name execution_time [28.803µs; 28.828µs] or [-0.043%; +0.043%] None None None
normalization/normalize_name/normalize_name/bad-name throughput [34688925.153op/s; 34718878.406op/s] or [-0.043%; +0.043%] None None None
normalization/normalize_name/normalize_name/good execution_time [16.673µs; 16.700µs] or [-0.079%; +0.079%] None None None
normalization/normalize_name/normalize_name/good throughput [59882628.376op/s; 59977550.358op/s] or [-0.079%; +0.079%] None None None

Group 2

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 63171ce 1725659685 levi/slice-ffi
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
tags/replace_trace_tags execution_time 2.614µs 2.659µs ± 0.015µs 2.660µs ± 0.008µs 2.665µs 2.694µs 2.699µs 2.701µs 1.55% 0.457 1.245 0.56% 0.001µs 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
tags/replace_trace_tags execution_time [2.657µs; 2.661µs] or [-0.078%; +0.078%] None None None

Group 3

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 63171ce 1725659685 levi/slice-ffi
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
concentrator/add_spans_to_concentrator execution_time 9.030ms 9.067ms ± 0.013ms 9.066ms ± 0.006ms 9.072ms 9.087ms 9.113ms 9.146ms 0.89% 1.458 6.823 0.15% 0.001ms 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
concentrator/add_spans_to_concentrator execution_time [9.065ms; 9.069ms] or [-0.021%; +0.021%] None None None

Group 4

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 63171ce 1725659685 levi/slice-ffi
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
benching deserializing traces from msgpack to their internal representation execution_time 1.190µs 1.366µs ± 0.054µs 1.381µs ± 0.033µs 1.409µs 1.441µs 1.455µs 1.456µs 5.44% -0.792 0.600 3.98% 0.004µs 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
benching deserializing traces from msgpack to their internal representation execution_time [1.358µs; 1.374µs] or [-0.553%; +0.553%] None None None

Group 5

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 63171ce 1725659685 levi/slice-ffi
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
redis/obfuscate_redis_string execution_time 38.495µs 38.937µs ± 0.719µs 38.622µs ± 0.063µs 38.691µs 40.421µs 40.440µs 42.192µs 9.24% 1.854 2.198 1.84% 0.051µs 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
redis/obfuscate_redis_string execution_time [38.837µs; 39.036µs] or [-0.256%; +0.256%] None None None

Group 6

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 63171ce 1725659685 levi/slice-ffi
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
credit_card/is_card_number/ execution_time 2.413µs 2.414µs ± 0.001µs 2.414µs ± 0.000µs 2.415µs 2.415µs 2.417µs 2.418µs 0.17% 1.479 4.551 0.03% 0.000µs 1 200
credit_card/is_card_number/ throughput 413524094.867op/s 414218229.399op/s ± 132051.009op/s 414238379.186op/s ± 80266.238op/s 414308911.462op/s 414379028.317op/s 414441954.114op/s 414442904.987op/s 0.05% -1.475 4.528 0.03% 9337.416op/s 1 200
credit_card/is_card_number/ 3782-8224-6310-005 execution_time 111.170µs 113.414µs ± 0.940µs 113.429µs ± 0.674µs 114.068µs 114.899µs 115.632µs 116.894µs 3.06% 0.233 0.176 0.83% 0.066µs 1 200
credit_card/is_card_number/ 3782-8224-6310-005 throughput 8554748.323op/s 8817887.275op/s ± 72946.162op/s 8816102.451op/s ± 52449.129op/s 8874513.954op/s 8926110.807op/s 8966836.776op/s 8995205.252op/s 2.03% -0.181 0.095 0.83% 5158.073op/s 1 200
credit_card/is_card_number/ 378282246310005 execution_time 107.149µs 107.925µs ± 0.417µs 107.851µs ± 0.242µs 108.128µs 108.730µs 109.110µs 109.370µs 1.41% 0.921 0.965 0.39% 0.029µs 1 200
credit_card/is_card_number/ 378282246310005 throughput 9143236.468op/s 9265852.800op/s ± 35688.049op/s 9272063.299op/s ± 20831.820op/s 9290004.652op/s 9315923.153op/s 9320506.206op/s 9332785.141op/s 0.65% -0.897 0.903 0.38% 2523.526op/s 1 200
credit_card/is_card_number/37828224631 execution_time 2.413µs 2.415µs ± 0.005µs 2.414µs ± 0.001µs 2.415µs 2.416µs 2.417µs 2.482µs 2.79% 13.600 186.899 0.20% 0.000µs 1 200
credit_card/is_card_number/37828224631 throughput 402964268.199op/s 414145191.398op/s ± 803398.290op/s 414213254.825op/s ± 87735.299op/s 414298830.986op/s 414352402.958op/s 414442577.385op/s 414446968.949op/s 0.06% -13.576 186.459 0.19% 56808.838op/s 1 200
credit_card/is_card_number/378282246310005 execution_time 104.419µs 104.995µs ± 0.417µs 104.871µs ± 0.221µs 105.203µs 105.803µs 106.221µs 106.330µs 1.39% 1.066 0.491 0.40% 0.029µs 1 200
credit_card/is_card_number/378282246310005 throughput 9404693.667op/s 9524447.203op/s ± 37634.358op/s 9535543.067op/s ± 20158.136op/s 9553151.821op/s 9567640.998op/s 9576085.345op/s 9576805.934op/s 0.43% -1.050 0.447 0.39% 2661.151op/s 1 200
credit_card/is_card_number/37828224631000521389798 execution_time 101.868µs 102.406µs ± 0.237µs 102.369µs ± 0.181µs 102.570µs 102.792µs 102.995µs 103.159µs 0.77% 0.394 -0.217 0.23% 0.017µs 1 200
credit_card/is_card_number/37828224631000521389798 throughput 9693774.648op/s 9765128.012op/s ± 22559.549op/s 9768537.981op/s ± 17241.737op/s 9782139.281op/s 9796045.831op/s 9810355.509op/s 9816629.370op/s 0.49% -0.383 -0.233 0.23% 1595.201op/s 1 200
credit_card/is_card_number/x371413321323331 execution_time 22.088µs 23.331µs ± 0.540µs 23.279µs ± 0.400µs 23.737µs 24.217µs 24.546µs 24.841µs 6.71% 0.129 -0.494 2.31% 0.038µs 1 200
credit_card/is_card_number/x371413321323331 throughput 40256330.543op/s 42883813.087op/s ± 990488.604op/s 42957374.177op/s ± 737141.646op/s 43534803.567op/s 44491596.396op/s 44933260.468op/s 45274134.887op/s 5.39% -0.027 -0.527 2.30% 70038.121op/s 1 200
credit_card/is_card_number_no_luhn/ execution_time 2.413µs 2.414µs ± 0.001µs 2.414µs ± 0.001µs 2.415µs 2.415µs 2.416µs 2.418µs 0.18% 1.465 5.968 0.03% 0.000µs 1 200
credit_card/is_card_number_no_luhn/ throughput 413499506.306op/s 414238520.242op/s ± 121164.231op/s 414256047.436op/s ± 86200.310op/s 414329603.850op/s 414393230.189op/s 414408442.407op/s 414473664.465op/s 0.05% -1.460 5.932 0.03% 8567.605op/s 1 200
credit_card/is_card_number_no_luhn/ 3782-8224-6310-005 execution_time 88.945µs 89.999µs ± 0.548µs 89.975µs ± 0.438µs 90.394µs 91.016µs 91.513µs 91.596µs 1.80% 0.618 -0.177 0.61% 0.039µs 1 200
credit_card/is_card_number_no_luhn/ 3782-8224-6310-005 throughput 10917500.929op/s 11111598.843op/s ± 67352.157op/s 11114209.538op/s ± 54147.152op/s 11169456.300op/s 11196019.368op/s 11221293.538op/s 11242861.160op/s 1.16% -0.592 -0.229 0.60% 4762.517op/s 1 200
credit_card/is_card_number_no_luhn/ 378282246310005 execution_time 85.221µs 86.112µs ± 0.378µs 86.103µs ± 0.220µs 86.284µs 86.599µs 87.189µs 88.926µs 3.28% 2.194 14.291 0.44% 0.027µs 1 200
credit_card/is_card_number_no_luhn/ 378282246310005 throughput 11245349.399op/s 11612958.489op/s ± 50515.558op/s 11614003.546op/s ± 29724.068op/s 11645832.033op/s 11678053.356op/s 11702271.168op/s 11734207.562op/s 1.03% -2.049 13.011 0.43% 3571.989op/s 1 200
credit_card/is_card_number_no_luhn/37828224631 execution_time 2.413µs 2.414µs ± 0.001µs 2.414µs ± 0.001µs 2.415µs 2.415µs 2.416µs 2.416µs 0.08% 0.254 -0.453 0.03% 0.000µs 1 200
credit_card/is_card_number_no_luhn/37828224631 throughput 413897068.735op/s 414242752.250op/s ± 112043.047op/s 414229886.687op/s ± 86807.966op/s 414341134.949op/s 414414828.504op/s 414444413.620op/s 414452816.218op/s 0.05% -0.253 -0.455 0.03% 7922.640op/s 1 200
credit_card/is_card_number_no_luhn/378282246310005 execution_time 82.465µs 83.098µs ± 0.281µs 83.063µs ± 0.173µs 83.256µs 83.564µs 84.020µs 84.080µs 1.23% 0.717 1.274 0.34% 0.020µs 1 200
credit_card/is_card_number_no_luhn/378282246310005 throughput 11893383.386op/s 12034138.627op/s ± 40669.818op/s 12039082.244op/s ± 25105.842op/s 12062370.532op/s 12092847.520op/s 12111689.587op/s 12126419.831op/s 0.73% -0.689 1.208 0.34% 2875.790op/s 1 200
credit_card/is_card_number_no_luhn/37828224631000521389798 execution_time 101.857µs 102.239µs ± 0.207µs 102.207µs ± 0.119µs 102.339µs 102.648µs 102.895µs 103.155µs 0.93% 1.221 2.440 0.20% 0.015µs 1 200
credit_card/is_card_number_no_luhn/37828224631000521389798 throughput 9694105.469op/s 9781020.847op/s ± 19790.306op/s 9784087.161op/s ± 11368.682op/s 9794089.267op/s 9807269.493op/s 9812238.858op/s 9817657.056op/s 0.34% -1.203 2.373 0.20% 1399.386op/s 1 200
credit_card/is_card_number_no_luhn/x371413321323331 execution_time 21.740µs 23.168µs ± 0.535µs 23.190µs ± 0.355µs 23.502µs 24.010µs 24.341µs 24.454µs 5.45% -0.056 -0.255 2.30% 0.038µs 1 200
credit_card/is_card_number_no_luhn/x371413321323331 throughput 40892748.473op/s 43185228.375op/s ± 999104.994op/s 43122819.808op/s ± 657899.934op/s 43906606.115op/s 44709282.656op/s 45681703.643op/s 45998002.982op/s 6.67% 0.178 -0.191 2.31% 70647.392op/s 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
credit_card/is_card_number/ execution_time [2.414µs; 2.414µs] or [-0.004%; +0.004%] None None None
credit_card/is_card_number/ throughput [414199928.399op/s; 414236530.399op/s] or [-0.004%; +0.004%] None None None
credit_card/is_card_number/ 3782-8224-6310-005 execution_time [113.283µs; 113.544µs] or [-0.115%; +0.115%] None None None
credit_card/is_card_number/ 3782-8224-6310-005 throughput [8807777.639op/s; 8827996.912op/s] or [-0.115%; +0.115%] None None None
credit_card/is_card_number/ 378282246310005 execution_time [107.867µs; 107.983µs] or [-0.054%; +0.054%] None None None
credit_card/is_card_number/ 378282246310005 throughput [9260906.780op/s; 9270798.820op/s] or [-0.053%; +0.053%] None None None
credit_card/is_card_number/37828224631 execution_time [2.414µs; 2.415µs] or [-0.028%; +0.028%] None None None
credit_card/is_card_number/37828224631 throughput [414033848.122op/s; 414256534.674op/s] or [-0.027%; +0.027%] None None None
credit_card/is_card_number/378282246310005 execution_time [104.937µs; 105.052µs] or [-0.055%; +0.055%] None None None
credit_card/is_card_number/378282246310005 throughput [9519231.442op/s; 9529662.963op/s] or [-0.055%; +0.055%] None None None
credit_card/is_card_number/37828224631000521389798 execution_time [102.373µs; 102.439µs] or [-0.032%; +0.032%] None None None
credit_card/is_card_number/37828224631000521389798 throughput [9762001.475op/s; 9768254.548op/s] or [-0.032%; +0.032%] None None None
credit_card/is_card_number/x371413321323331 execution_time [23.256µs; 23.406µs] or [-0.321%; +0.321%] None None None
credit_card/is_card_number/x371413321323331 throughput [42746540.893op/s; 43021085.282op/s] or [-0.320%; +0.320%] None None None
credit_card/is_card_number_no_luhn/ execution_time [2.414µs; 2.414µs] or [-0.004%; +0.004%] None None None
credit_card/is_card_number_no_luhn/ throughput [414221728.045op/s; 414255312.439op/s] or [-0.004%; +0.004%] None None None
credit_card/is_card_number_no_luhn/ 3782-8224-6310-005 execution_time [89.923µs; 90.075µs] or [-0.084%; +0.084%] None None None
credit_card/is_card_number_no_luhn/ 3782-8224-6310-005 throughput [11102264.482op/s; 11120933.204op/s] or [-0.084%; +0.084%] None None None
credit_card/is_card_number_no_luhn/ 378282246310005 execution_time [86.060µs; 86.165µs] or [-0.061%; +0.061%] None None None
credit_card/is_card_number_no_luhn/ 378282246310005 throughput [11605957.518op/s; 11619959.459op/s] or [-0.060%; +0.060%] None None None
credit_card/is_card_number_no_luhn/37828224631 execution_time [2.414µs; 2.414µs] or [-0.004%; +0.004%] None None None
credit_card/is_card_number_no_luhn/37828224631 throughput [414227224.162op/s; 414258280.339op/s] or [-0.004%; +0.004%] None None None
credit_card/is_card_number_no_luhn/378282246310005 execution_time [83.059µs; 83.137µs] or [-0.047%; +0.047%] None None None
credit_card/is_card_number_no_luhn/378282246310005 throughput [12028502.181op/s; 12039775.072op/s] or [-0.047%; +0.047%] None None None
credit_card/is_card_number_no_luhn/37828224631000521389798 execution_time [102.210µs; 102.268µs] or [-0.028%; +0.028%] None None None
credit_card/is_card_number_no_luhn/37828224631000521389798 throughput [9778278.101op/s; 9783763.593op/s] or [-0.028%; +0.028%] None None None
credit_card/is_card_number_no_luhn/x371413321323331 execution_time [23.094µs; 23.242µs] or [-0.320%; +0.320%] None None None
credit_card/is_card_number_no_luhn/x371413321323331 throughput [43046762.032op/s; 43323694.718op/s] or [-0.321%; +0.321%] None None None

Group 7

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 63171ce 1725659685 levi/slice-ffi
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
benching string interning on wordpress profile execution_time 136.668µs 136.987µs ± 0.178µs 136.963µs ± 0.113µs 137.088µs 137.317µs 137.476µs 137.621µs 0.48% 0.713 0.627 0.13% 0.013µs 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
benching string interning on wordpress profile execution_time [136.962µs; 137.011µs] or [-0.018%; +0.018%] None None None

Group 8

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 63171ce 1725659685 levi/slice-ffi
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
normalization/normalize_trace/test_trace execution_time 295.219ns 308.043ns ± 15.368ns 300.919ns ± 4.307ns 312.811ns 341.143ns 354.119ns 354.138ns 17.69% 1.521 1.275 4.98% 1.087ns 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
normalization/normalize_trace/test_trace execution_time [305.913ns; 310.173ns] or [-0.691%; +0.691%] None None None

Group 9

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 63171ce 1725659685 levi/slice-ffi
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
write only interface execution_time 1.399µs 2.910µs ± 1.387µs 2.752µs ± 0.023µs 2.773µs 3.035µs 12.574µs 15.773µs 473.16% 7.964 63.567 47.53% 0.098µs 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
write only interface execution_time [2.718µs; 3.103µs] or [-6.604%; +6.604%] None None None

Group 10

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 63171ce 1725659685 levi/slice-ffi
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
two way interface execution_time 16.974µs 22.908µs ± 14.056µs 17.275µs ± 0.104µs 17.446µs 49.783µs 51.662µs 120.650µs 598.40% 3.748 19.235 61.20% 0.994µs 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
two way interface execution_time [20.960µs; 24.856µs] or [-8.504%; +8.504%] None None None

Group 11

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 63171ce 1725659685 levi/slice-ffi
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
sql/obfuscate_sql_string execution_time 75.218µs 75.357µs ± 0.146µs 75.341µs ± 0.036µs 75.382µs 75.431µs 75.771µs 77.139µs 2.39% 9.452 110.401 0.19% 0.010µs 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
sql/obfuscate_sql_string execution_time [75.337µs; 75.377µs] or [-0.027%; +0.027%] None None None

Group 12

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 63171ce 1725659685 levi/slice-ffi
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
normalization/normalize_service/normalize_service/A0000000000000000000000000000000000000000000000000... execution_time 618.468µs 618.979µs ± 0.252µs 618.955µs ± 0.164µs 619.131µs 619.418µs 619.556µs 620.147µs 0.19% 0.650 1.482 0.04% 0.018µs 1 200
normalization/normalize_service/normalize_service/A0000000000000000000000000000000000000000000000000... throughput 1612521.076op/s 1615563.566op/s ± 657.276op/s 1615625.816op/s ± 428.402op/s 1615999.298op/s 1616565.442op/s 1616803.085op/s 1616899.750op/s 0.08% -0.647 1.468 0.04% 46.476op/s 1 200
normalization/normalize_service/normalize_service/Data🐨dog🐶 繋がっ⛰てて execution_time 465.949µs 467.318µs ± 0.901µs 467.113µs ± 0.603µs 467.919µs 469.029µs 469.623µs 469.688µs 0.55% 0.689 -0.232 0.19% 0.064µs 1 200
normalization/normalize_service/normalize_service/Data🐨dog🐶 繋がっ⛰てて throughput 2129072.439op/s 2139880.269op/s ± 4118.611op/s 2140811.784op/s ± 2764.768op/s 2143194.857op/s 2145224.010op/s 2145969.481op/s 2146155.687op/s 0.25% -0.682 -0.246 0.19% 291.230op/s 1 200
normalization/normalize_service/normalize_service/Test Conversion 0f Weird !@#$%^&**() Characters execution_time 190.444µs 190.680µs ± 0.112µs 190.673µs ± 0.078µs 190.749µs 190.850µs 190.914µs 191.210µs 0.28% 0.669 1.574 0.06% 0.008µs 1 200
normalization/normalize_service/normalize_service/Test Conversion 0f Weird !@#$%^&**() Characters throughput 5229849.891op/s 5244393.088op/s ± 3066.119op/s 5244576.453op/s ± 2141.898op/s 5246781.705op/s 5248846.854op/s 5249841.110op/s 5250883.158op/s 0.12% -0.663 1.551 0.06% 216.807op/s 1 200
normalization/normalize_service/normalize_service/[empty string] execution_time 46.610µs 47.274µs ± 0.207µs 47.278µs ± 0.161µs 47.447µs 47.573µs 47.674µs 47.725µs 0.95% -0.274 -0.341 0.44% 0.015µs 1 200
normalization/normalize_service/normalize_service/[empty string] throughput 20953167.109op/s 21153760.375op/s ± 92670.029op/s 21151400.054op/s ± 71882.602op/s 21221454.234op/s 21306871.878op/s 21349506.768op/s 21454424.782op/s 1.43% 0.295 -0.315 0.44% 6552.761op/s 1 200
normalization/normalize_service/normalize_service/test_ASCII execution_time 51.416µs 51.686µs ± 0.102µs 51.679µs ± 0.064µs 51.743µs 51.882µs 51.931µs 51.945µs 0.51% 0.187 0.104 0.20% 0.007µs 1 200
normalization/normalize_service/normalize_service/test_ASCII throughput 19251258.952op/s 19347645.643op/s ± 38283.675op/s 19350117.121op/s ± 24072.470op/s 19374363.744op/s 19406611.889op/s 19430435.150op/s 19449086.113op/s 0.51% -0.174 0.102 0.20% 2707.065op/s 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
normalization/normalize_service/normalize_service/A0000000000000000000000000000000000000000000000000... execution_time [618.944µs; 619.014µs] or [-0.006%; +0.006%] None None None
normalization/normalize_service/normalize_service/A0000000000000000000000000000000000000000000000000... throughput [1615472.474op/s; 1615654.659op/s] or [-0.006%; +0.006%] None None None
normalization/normalize_service/normalize_service/Data🐨dog🐶 繋がっ⛰てて execution_time [467.193µs; 467.442µs] or [-0.027%; +0.027%] None None None
normalization/normalize_service/normalize_service/Data🐨dog🐶 繋がっ⛰てて throughput [2139309.469op/s; 2140451.069op/s] or [-0.027%; +0.027%] None None None
normalization/normalize_service/normalize_service/Test Conversion 0f Weird !@#$%^&**() Characters execution_time [190.664µs; 190.695µs] or [-0.008%; +0.008%] None None None
normalization/normalize_service/normalize_service/Test Conversion 0f Weird !@#$%^&**() Characters throughput [5243968.154op/s; 5244818.023op/s] or [-0.008%; +0.008%] None None None
normalization/normalize_service/normalize_service/[empty string] execution_time [47.245µs; 47.302µs] or [-0.061%; +0.061%] None None None
normalization/normalize_service/normalize_service/[empty string] throughput [21140917.200op/s; 21166603.549op/s] or [-0.061%; +0.061%] None None None
normalization/normalize_service/normalize_service/test_ASCII execution_time [51.672µs; 51.700µs] or [-0.027%; +0.027%] None None None
normalization/normalize_service/normalize_service/test_ASCII throughput [19342339.894op/s; 19352951.392op/s] or [-0.027%; +0.027%] None None None

Baseline

Omitted due to size.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Aug 29, 2024

Codecov Report

Attention: Patch coverage is 95.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 72.62%. Comparing base (cef5282) to head (63171ce).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #604      +/-   ##
==========================================
+ Coverage   72.60%   72.62%   +0.02%     
==========================================
  Files         246      246              
  Lines       34971    35005      +34     
==========================================
+ Hits        25390    25423      +33     
- Misses       9581     9582       +1     
Components Coverage Δ
crashtracker 20.38% <ø> (-0.06%) ⬇️
datadog-alloc 98.73% <ø> (ø)
data-pipeline 90.12% <ø> (ø)
data-pipeline-ffi 0.00% <ø> (ø)
ddcommon 83.08% <95.00%> (+0.25%) ⬆️
ddcommon-ffi 69.52% <95.00%> (+1.40%) ⬆️
ddtelemetry 59.02% <ø> (ø)
ipc 83.61% <ø> (ø)
profiling 84.26% <ø> (ø)
profiling-ffi 77.42% <ø> (ø)
serverless 0.00% <ø> (ø)
sidecar 40.13% <ø> (ø)
sidecar-ffi 0.00% <ø> (ø)
spawn-worker 50.36% <ø> (ø)
tinybytes 91.66% <ø> (ø)
trace-mini-agent 70.88% <ø> (ø)
trace-normalization 98.25% <ø> (ø)
trace-obfuscation 95.73% <ø> (ø)
trace-protobuf 77.67% <ø> (ø)
trace-utils 92.83% <ø> (ø)

@ivoanjo
Copy link
Copy Markdown
Member

ivoanjo commented Aug 30, 2024

I'm not a fan of this approach 😓. From our discussion on slack, the underlying assumption here is that we would catch all such crashes in development. And... I'm slightly suspicious that such an assumption would always hold.

The penalty of getting the assumption wrong is blowing up the client application, which is quite high... 💥

My suggestion is to change this to reporting back an API failure: This would equally be caught in development (as we're supposed to check errors on all datadog API calls already!), and in the off chance we never trigger the exact set of circumstances that would cause this error to show up, the penalty in production is that the profiler would get an error, which again we should already be handling.


(If I'll be honest, I'd actually prefer to go with option 3: Libdatadog should correctly handle NULLs in this situation.

A NULL is a very natural thing for C-like languages, and I think we're leaking Rust details back to the API callers by forcing this to not be NULL. E.g. consider this: if Slice::from_raw_parts stated in its docs that a (NULL, 0) is fine for a slice, would we still force this constraint on our ffi? If not, does that not point to rust details leaking back, rather than actual intent in API design?)

@morrisonlevi
Copy link
Copy Markdown
Contributor Author

morrisonlevi commented Sep 4, 2024

I experimented with getting rid of most of the existing API and replacing it with a Result return.

% git diff --shortstat                                         
 22 files changed, 860 insertions(+), 507 deletions(-)

I still have pages of errors to fix.

I am okay if we go down this route, but it's not a good idea to do that without more discussion. It touches crash tracking, telemetry, profiling, and data pipeline. Maybe more, since I'm not finished. I can open this as a draft PR, if people want.

@ivoanjo
Copy link
Copy Markdown
Member

ivoanjo commented Sep 5, 2024

Fair enough, I agree the error approach "sounds good" has a big ripple effect in a lot of code/APIs.

How much do you dislike my suggestion of having the ffi code take care of handling nulls so the resulting API is more friendly to ffi callers?

I don't mind taking it up myself and writing such a PR.

If we have to, I believe we can live with this PR as-is but... I really do fear it's a really big sharp edge of the "oops you forgot you couldn't do this very natural/straightforward thing (from a caller POV) in this corner case and we blew up in production" kind 😅

@morrisonlevi
Copy link
Copy Markdown
Contributor Author

morrisonlevi commented Sep 5, 2024

How much do you dislike my suggestion of having the ffi code take care of handling nulls so the resulting API is more friendly to ffi callers?

The PR handles slices with null pointers when the length is zero. It panics when:

  1. The pointer is null and length is non-zero.
  2. The pointer is mis-aligned for the slice type.
  3. The length is larger than isize::MAX (I added this point after you last reviewed). In practice this is unlikely to occur except by error/corruption, since mostly we run on 64-bit platforms, and no systems have that many bits of physical memory.

So it "handles" null pointers for the only case it could be reasonable. These checks will slow down the code, of course.

Copy link
Copy Markdown
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

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

Ack, I think the current version is quite reasonable. 🙏

LGTM 👍

@morrisonlevi morrisonlevi merged commit a82cd6c into main Sep 6, 2024
@morrisonlevi morrisonlevi deleted the levi/slice-ffi branch September 6, 2024 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants