diff --git a/benchmarks/shared-json-buffer-lifetime-20261017.json b/benchmarks/shared-json-buffer-lifetime-20261017.json new file mode 100644 index 000000000..d618906ed --- /dev/null +++ b/benchmarks/shared-json-buffer-lifetime-20261017.json @@ -0,0 +1,379 @@ +{ + "scope": "Assets + BlockFacts + Behaviours loader only; no full startup or first frame", + "resources": "/srv/bob-data/horizon/.local/horizon-client/26.3", + "repeats": 10, + "ordering": [ + [ + "released", + "retained" + ], + [ + "retained", + "released" + ], + [ + "released", + "retained" + ], + [ + "retained", + "released" + ], + [ + "released", + "retained" + ], + [ + "retained", + "released" + ], + [ + "released", + "retained" + ], + [ + "retained", + "released" + ], + [ + "released", + "retained" + ], + [ + "retained", + "released" + ] + ], + "load_average_before": [ + 8.2421875, + 6.56396484375, + 6.39208984375 + ], + "load_average_after": [ + 7.98095703125, + 6.6455078125, + 6.4248046875 + ], + "executables": { + "released": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-integrated", + "mode": "deferred", + "sha256": "a52d6a7efc7b3198ef0dd8150325f56a3fe5d0c5883fd6d14c4b0c281866ce7c" + }, + "retained": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-integrated", + "mode": "deferred-held", + "sha256": "a52d6a7efc7b3198ef0dd8150325f56a3fe5d0c5883fd6d14c4b0c281866ce7c" + } + }, + "metrics": { + "released": { + "phase_ms": { + "median": 482.591, + "p25": 444.276, + "p75": 586.92, + "min": 430.128, + "max": 736.543, + "samples": [ + 529.244, + 606.146, + 449.23, + 442.624, + 669.108, + 511.519, + 736.543, + 432.616, + 430.128, + 453.663 + ] + }, + "total_ms": { + "median": 987.004, + "p25": 932.885, + "p75": 1134.876, + "min": 914.242, + "max": 1201.759, + "samples": [ + 1055.119, + 1161.462, + 968.629, + 914.242, + 1201.759, + 1005.379, + 1200.01, + 928.249, + 935.775, + 931.921 + ] + }, + "cpu_ms": { + "median": 1004.675, + "p25": 936.465, + "p75": 1116.791, + "min": 908.327, + "max": 1241.168, + "samples": [ + 1074.425, + 1130.913, + 984.832, + 931.205, + 1186.169, + 1024.519, + 1241.168, + 908.327, + 952.245, + 927.15 + ] + }, + "peak_rss_kib": { + "median": 268124.0, + "p25": 267753.0, + "p75": 268455.0, + "min": 267708, + "max": 268700, + "samples": [ + 268268, + 268500, + 267744, + 267724, + 267708, + 267780, + 268700, + 268496, + 268332, + 267980 + ] + }, + "behaviour_json_ms": { + "median": 24.371, + "p25": 22.469, + "p75": 28.486, + "min": 20.662, + "max": 35.297, + "samples": [ + 33.387, + 35.297, + 24.732, + 24.011, + 27.699, + 28.748, + 23.623, + 22.084, + 20.662, + 21.266 + ] + }, + "facts_ms": { + "median": 292.77, + "p25": 270.649, + "p75": 383.193, + "min": 264.691, + "max": 443.291, + "samples": [ + 346.613, + 398.468, + 274.673, + 264.691, + 443.291, + 292.926, + 395.387, + 267.232, + 269.308, + 292.615 + ] + }, + "behaviours_ms": { + "median": 148.635, + "p25": 141.329, + "p75": 181.741, + "min": 136.361, + "max": 307.004, + "samples": [ + 145.009, + 168.982, + 146.535, + 150.736, + 194.604, + 185.994, + 307.004, + 140.102, + 136.785, + 136.361 + ] + }, + "post_rss_kib": { + "median": 268668.0, + "p25": 268246.0, + "p75": 268922.0, + "min": 268048.0, + "max": 269012.0, + "samples": [ + 268668.0, + 268936.0, + 268108.0, + 268088.0, + 268048.0, + 268668.0, + 268880.0, + 269012.0, + 268960.0, + 268660.0 + ] + } + }, + "retained": { + "phase_ms": { + "median": 487.954, + "p25": 471.456, + "p75": 531.586, + "min": 401.516, + "max": 834.154, + "samples": [ + 486.974, + 613.755, + 540.535, + 470.333, + 488.934, + 474.825, + 834.154, + 504.74, + 401.516, + 440.381 + ] + }, + "total_ms": { + "median": 1038.875, + "p25": 989.724, + "p75": 1079.197, + "min": 880.933, + "max": 1746.386, + "samples": [ + 996.407, + 1067.467, + 1082.69, + 1103.131, + 1010.283, + 1068.719, + 1746.386, + 987.496, + 890.46, + 880.933 + ] + }, + "cpu_ms": { + "median": 1035.537, + "p25": 982.276, + "p75": 1082.698, + "min": 908.774, + "max": 1660.068, + "samples": [ + 1011.712, + 1087.688, + 1076.523, + 1084.757, + 998.654, + 1059.363, + 1660.068, + 976.817, + 912.849, + 908.774 + ] + }, + "peak_rss_kib": { + "median": 268150.0, + "p25": 267537.0, + "p75": 268614.0, + "min": 267268, + "max": 268848, + "samples": [ + 268748, + 267968, + 267268, + 268332, + 267540, + 268560, + 267492, + 268632, + 267536, + 268848 + ] + }, + "behaviour_json_ms": { + "median": 23.208, + "p25": 22.305, + "p75": 26.544, + "min": 20.059, + "max": 32.669, + "samples": [ + 32.669, + 22.62, + 22.2, + 27.331, + 25.088, + 27.029, + 23.488, + 20.977, + 22.928, + 20.059 + ] + }, + "facts_ms": { + "median": 304.44, + "p25": 291.562, + "p75": 330.991, + "min": 244.758, + "max": 384.634, + "samples": [ + 307.936, + 374.145, + 336.931, + 300.944, + 290.81, + 293.817, + 384.634, + 313.171, + 244.758, + 279.303 + ] + }, + "behaviours_ms": { + "median": 162.285, + "p25": 143.135, + "p75": 179.31, + "min": 133.83, + "max": 426.031, + "samples": [ + 146.367, + 216.988, + 181.402, + 142.058, + 173.036, + 153.978, + 426.031, + 170.592, + 133.83, + 141.017 + ] + }, + "post_rss_kib": { + "median": 268694.0, + "p25": 268116.0, + "p75": 269056.0, + "min": 267988.0, + "max": 269212.0, + "samples": [ + 269212.0, + 268564.0, + 268096.0, + 268824.0, + 268176.0, + 269032.0, + 267988.0, + 269064.0, + 268044.0, + 269120.0 + ] + } + } + } +} diff --git a/benchmarks/shared-json-decoder-phases-20261017.json b/benchmarks/shared-json-decoder-phases-20261017.json new file mode 100644 index 000000000..8c5880124 --- /dev/null +++ b/benchmarks/shared-json-decoder-phases-20261017.json @@ -0,0 +1,176 @@ +{ + "scope": "Isolated gameplay-facts.json validation/typed decoding; includes JSON file read", + "resources": "/srv/bob-data/horizon/.local/horizon-client/26.3", + "repeats": 10, + "load_averages_before_after": [ + [ + 14.7451171875, + 8.8994140625, + 6.89599609375 + ], + [ + 14.7451171875, + 8.8994140625, + 6.89599609375 + ] + ], + "binary_sha256": "c2be9140c792720499d70c5806b8def0472734264ad72486d01365447e0cc2d7", + "metrics": { + "validate": { + "phase_ms": { + "median": 117.417, + "p25": 114.101, + "p75": 158.855, + "min": 109.199, + "max": 173.408, + "samples": [ + 109.199, + 113.958, + 110.195, + 118.987, + 171.275, + 124.701, + 170.24, + 173.408, + 115.848, + 114.531 + ] + }, + "total_ms": { + "median": 139.933, + "p25": 133.863, + "p75": 193.565, + "min": 129.75, + "max": 276.311, + "samples": [ + 276.311, + 135.448, + 129.75, + 138.452, + 195.127, + 141.413, + 188.88, + 199.802, + 133.335, + 132.094 + ] + }, + "cpu_ms": { + "median": 138.849, + "p25": 134.285, + "p75": 168.881, + "min": 129.089, + "max": 190.82, + "samples": [ + 140.962, + 136.06, + 129.089, + 139.059, + 189.478, + 138.639, + 178.187, + 190.82, + 133.693, + 132.716 + ] + }, + "peak_rss_kib": { + "median": 56654.0, + "p25": 56642.0, + "p75": 56704.0, + "min": 56616, + "max": 56724, + "samples": [ + 56620, + 56656, + 56640, + 56720, + 56616, + 56724, + 56652, + 56720, + 56648, + 56656 + ] + } + }, + "typed": { + "phase_ms": { + "median": 115.873, + "p25": 109.422, + "p75": 129.67, + "min": 100.872, + "max": 183.923, + "samples": [ + 116.965, + 132.071, + 100.872, + 105.098, + 122.468, + 170.777, + 107.997, + 183.923, + 113.699, + 114.781 + ] + }, + "total_ms": { + "median": 133.883, + "p25": 126.939, + "p75": 155.913, + "min": 117.54, + "max": 210.164, + "samples": [ + 135.04, + 159.38, + 117.54, + 122.391, + 145.512, + 189.132, + 125.846, + 210.164, + 130.217, + 132.727 + ] + }, + "cpu_ms": { + "median": 134.375, + "p25": 126.231, + "p75": 154.675, + "min": 118.132, + "max": 204.242, + "samples": [ + 135.633, + 157.961, + 118.132, + 122.77, + 144.816, + 178.293, + 124.755, + 204.242, + 130.661, + 133.117 + ] + }, + "peak_rss_kib": { + "median": 83974.0, + "p25": 82744.0, + "p75": 84490.0, + "min": 82332, + "max": 84596, + "samples": [ + 83596, + 84596, + 82332, + 82424, + 84288, + 82460, + 84532, + 83660, + 84364, + 84536 + ] + } + } + } +} diff --git a/benchmarks/shared-json-five-way-20261017.json b/benchmarks/shared-json-five-way-20261017.json new file mode 100644 index 000000000..61dcb7c3d --- /dev/null +++ b/benchmarks/shared-json-five-way-20261017.json @@ -0,0 +1,453 @@ +{ + "scope": "Assets + BlockFacts + Behaviours loader only; no full startup or first frame", + "resources": "/srv/bob-data/horizon/.local/horizon-client/26.3", + "repeats": 8, + "ordering": [ + [ + "baseline", + "a01d47f2", + "cf837118", + "cd61e11b", + "current" + ], + [ + "current", + "cd61e11b", + "cf837118", + "a01d47f2", + "baseline" + ], + [ + "baseline", + "a01d47f2", + "cf837118", + "cd61e11b", + "current" + ], + [ + "current", + "cd61e11b", + "cf837118", + "a01d47f2", + "baseline" + ], + [ + "baseline", + "a01d47f2", + "cf837118", + "cd61e11b", + "current" + ], + [ + "current", + "cd61e11b", + "cf837118", + "a01d47f2", + "baseline" + ], + [ + "baseline", + "a01d47f2", + "cf837118", + "cd61e11b", + "current" + ], + [ + "current", + "cd61e11b", + "cf837118", + "a01d47f2", + "baseline" + ] + ], + "load_average_before": [ + 10.57958984375, + 8.45947265625, + 6.8134765625 + ], + "load_average_after": [ + 7.158203125, + 7.7998046875, + 6.66455078125 + ], + "executables": { + "baseline": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-e422bd13", + "mode": "baseline", + "sha256": "bf61f2e6c92e001be3c3bc93cf8072cc6af6fd1d7bcfa7273045960948ec89e7" + }, + "a01d47f2": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-a01d47f2", + "mode": "shared", + "sha256": "88be56f8dbd28d0b4abd6c672486ba758df96ba18f68da45b94db14231dd3eea" + }, + "cf837118": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-cf837118", + "mode": "deferred", + "sha256": "f1b044cd9ac2f67c644fb40bd7ecbe38128ec739a8112d57fc36f05fe9036a52" + }, + "cd61e11b": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-cd61e11b", + "mode": "deferred", + "sha256": "fb2d3725b09ee38f85b49901f7053a6fe339b980a2b2dac6930a8ded22c139e8" + }, + "current": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-new", + "mode": "deferred", + "sha256": "84eb1baae8e138f52e300b0b44f1339fca38e70db6e06126e78db776ea3e5cd0" + } + }, + "metrics": { + "baseline": { + "phase_ms": { + "median": 1277.781, + "p25": 1271.23, + "p75": 1296.157, + "min": 1223.341, + "max": 1338.745, + "samples": [ + 1265.934, + 1223.341, + 1274.931, + 1289.177, + 1338.745, + 1317.096, + 1272.995, + 1280.631 + ] + }, + "total_ms": { + "median": 1711.802, + "p25": 1695.745, + "p75": 1754.276, + "min": 1645.69, + "max": 2887.078, + "samples": [ + 2887.078, + 1645.69, + 1690.413, + 1711.459, + 1761.859, + 1751.748, + 1697.522, + 1712.144 + ] + }, + "cpu_ms": { + "median": 1769.996, + "p25": 1748.925, + "p75": 1807.254, + "min": 1705.167, + "max": 1950.463, + "samples": [ + 1950.463, + 1705.167, + 1749.023, + 1768.05, + 1804.543, + 1815.386, + 1771.942, + 1748.632 + ] + }, + "peak_rss_kib": { + "median": 820180.0, + "p25": 820030.0, + "p75": 820502.0, + "min": 819472, + "max": 820884, + "samples": [ + 819472, + 820416, + 820060, + 820096, + 820264, + 820884, + 819940, + 820760 + ] + } + }, + "a01d47f2": { + "phase_ms": { + "median": 430.783, + "p25": 427.542, + "p75": 451.763, + "min": 423.035, + "max": 550.345, + "samples": [ + 491.599, + 423.035, + 428.85, + 427.694, + 432.715, + 427.084, + 438.484, + 550.345 + ] + }, + "total_ms": { + "median": 868.457, + "p25": 863.709, + "p75": 932.066, + "min": 837.75, + "max": 997.779, + "samples": [ + 911.935, + 837.75, + 865.419, + 868.626, + 858.578, + 997.779, + 868.288, + 992.46 + ] + }, + "cpu_ms": { + "median": 897.639, + "p25": 887.661, + "p75": 944.363, + "min": 865.497, + "max": 1001.635, + "samples": [ + 925.321, + 865.497, + 899.505, + 895.774, + 876.929, + 1001.635, + 891.239, + 1001.488 + ] + }, + "peak_rss_kib": { + "median": 351906.0, + "p25": 351505.0, + "p75": 352181.0, + "min": 351176, + "max": 352440, + "samples": [ + 352008, + 352120, + 351352, + 351556, + 351804, + 351176, + 352440, + 352364 + ] + } + }, + "cf837118": { + "phase_ms": { + "median": 408.459, + "p25": 398.987, + "p75": 428.585, + "min": 387.999, + "max": 524.425, + "samples": [ + 433.521, + 387.999, + 412.195, + 397.366, + 404.724, + 399.527, + 426.939, + 524.425 + ] + }, + "total_ms": { + "median": 851.294, + "p25": 823.291, + "p75": 890.55, + "min": 801.356, + "max": 1030.737, + "samples": [ + 892.054, + 801.356, + 840.381, + 818.285, + 862.208, + 824.96, + 890.049, + 1030.737 + ] + }, + "cpu_ms": { + "median": 870.765, + "p25": 850.849, + "p75": 907.922, + "min": 825.718, + "max": 1041.996, + "samples": [ + 906.657, + 825.718, + 866.472, + 843.591, + 875.058, + 853.268, + 911.715, + 1041.996 + ] + }, + "peak_rss_kib": { + "median": 274172.0, + "p25": 273909.0, + "p75": 274438.0, + "min": 273668, + "max": 274964, + "samples": [ + 274372, + 274964, + 273668, + 273972, + 274552, + 274400, + 273840, + 273932 + ] + } + }, + "cd61e11b": { + "phase_ms": { + "median": 419.114, + "p25": 404.191, + "p75": 460.634, + "min": 388.557, + "max": 735.687, + "samples": [ + 457.971, + 418.303, + 388.557, + 405.041, + 419.925, + 401.64, + 468.624, + 735.687 + ] + }, + "total_ms": { + "median": 840.723, + "p25": 835.398, + "p75": 917.995, + "min": 811.43, + "max": 1565.471, + "samples": [ + 906.328, + 837.706, + 811.43, + 835.727, + 843.74, + 834.412, + 952.996, + 1565.471 + ] + }, + "cpu_ms": { + "median": 863.404, + "p25": 858.916, + "p75": 934.2, + "min": 833.955, + "max": 1550.132, + "samples": [ + 916.017, + 864.82, + 833.955, + 859.057, + 861.989, + 858.494, + 988.748, + 1550.132 + ] + }, + "peak_rss_kib": { + "median": 267508.0, + "p25": 267310.0, + "p75": 267890.0, + "min": 267172, + "max": 268412, + "samples": [ + 267304, + 268292, + 267312, + 267756, + 267340, + 267676, + 267172, + 268412 + ] + } + }, + "current": { + "phase_ms": { + "median": 406.779, + "p25": 397.839, + "p75": 413.957, + "min": 385.028, + "max": 552.051, + "samples": [ + 387.136, + 385.028, + 409.317, + 404.242, + 401.407, + 411.451, + 421.476, + 552.051 + ] + }, + "total_ms": { + "median": 819.787, + "p25": 814.211, + "p75": 855.69, + "min": 800.867, + "max": 1128.453, + "samples": [ + 808.685, + 800.867, + 816.053, + 817.907, + 821.667, + 843.26, + 892.982, + 1128.453 + ] + }, + "cpu_ms": { + "median": 847.078, + "p25": 836.598, + "p75": 877.524, + "min": 826.002, + "max": 1134.369, + "samples": [ + 834.665, + 826.002, + 837.243, + 842.86, + 851.296, + 864.892, + 915.419, + 1134.369 + ] + }, + "peak_rss_kib": { + "median": 267956.0, + "p25": 267612.0, + "p75": 268326.0, + "min": 267308, + "max": 268428, + "samples": [ + 268428, + 267308, + 268260, + 267516, + 267652, + 268312, + 268368, + 267644 + ] + } + } + }, + "experiment_note": "Experimental projection variant (reused sounds, Arc-keyed string pools and direct flags); reverted after mixed CPU/RSS evidence. Current in this file is not the final PR version." +} diff --git a/benchmarks/shared-json-five-way-final-20261017.json b/benchmarks/shared-json-five-way-final-20261017.json new file mode 100644 index 000000000..ce92b7b61 --- /dev/null +++ b/benchmarks/shared-json-five-way-final-20261017.json @@ -0,0 +1,582 @@ +{ + "scope": "Assets + BlockFacts + Behaviours loader only; no full startup or first frame", + "resources": "/srv/bob-data/horizon/.local/horizon-client/26.3", + "repeats": 10, + "ordering": [ + [ + "baseline", + "a01d47f2", + "cf837118", + "cd61e11b", + "current" + ], + [ + "current", + "cd61e11b", + "cf837118", + "a01d47f2", + "baseline" + ], + [ + "baseline", + "a01d47f2", + "cf837118", + "cd61e11b", + "current" + ], + [ + "current", + "cd61e11b", + "cf837118", + "a01d47f2", + "baseline" + ], + [ + "baseline", + "a01d47f2", + "cf837118", + "cd61e11b", + "current" + ], + [ + "current", + "cd61e11b", + "cf837118", + "a01d47f2", + "baseline" + ], + [ + "baseline", + "a01d47f2", + "cf837118", + "cd61e11b", + "current" + ], + [ + "current", + "cd61e11b", + "cf837118", + "a01d47f2", + "baseline" + ], + [ + "baseline", + "a01d47f2", + "cf837118", + "cd61e11b", + "current" + ], + [ + "current", + "cd61e11b", + "cf837118", + "a01d47f2", + "baseline" + ] + ], + "load_average_before": [ + 11.4921875, + 7.46875, + 6.69677734375 + ], + "load_average_after": [ + 17.763671875, + 11.39013671875, + 8.20556640625 + ], + "executables": { + "baseline": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-e422bd13", + "mode": "baseline", + "sha256": "bf61f2e6c92e001be3c3bc93cf8072cc6af6fd1d7bcfa7273045960948ec89e7" + }, + "a01d47f2": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-a01d47f2", + "mode": "shared", + "sha256": "88be56f8dbd28d0b4abd6c672486ba758df96ba18f68da45b94db14231dd3eea" + }, + "cf837118": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-cf837118", + "mode": "deferred", + "sha256": "f1b044cd9ac2f67c644fb40bd7ecbe38128ec739a8112d57fc36f05fe9036a52" + }, + "cd61e11b": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-cd61e11b", + "mode": "deferred", + "sha256": "fb2d3725b09ee38f85b49901f7053a6fe339b980a2b2dac6930a8ded22c139e8" + }, + "current": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-integrated", + "mode": "deferred", + "sha256": "a52d6a7efc7b3198ef0dd8150325f56a3fe5d0c5883fd6d14c4b0c281866ce7c" + } + }, + "metrics": { + "baseline": { + "phase_ms": { + "median": 1506.588, + "p25": 1388.314, + "p75": 2119.85, + "min": 1319.319, + "max": 3143.124, + "samples": [ + 3143.124, + 2483.307, + 2124.952, + 2104.544, + 1525.153, + 1396.75, + 1381.771, + 1488.022, + 1385.502, + 1319.319 + ] + }, + "total_ms": { + "median": 1962.122, + "p25": 1858.188, + "p75": 3152.608, + "min": 1804.713, + "max": 4136.912, + "samples": [ + 4136.912, + 3250.285, + 3134.13, + 3158.767, + 2001.229, + 1883.076, + 1849.892, + 1923.016, + 1818.34, + 1804.713 + ] + }, + "cpu_ms": { + "median": 1969.296, + "p25": 1893.348, + "p75": 2694.824, + "min": 1842.049, + "max": 3059.824, + "samples": [ + 3059.824, + 2765.392, + 2698.837, + 2682.786, + 2026.89, + 1911.703, + 1888.282, + 1908.545, + 1859.233, + 1842.049 + ] + }, + "peak_rss_kib": { + "median": 819952.0, + "p25": 819778.0, + "p75": 820164.0, + "min": 818944, + "max": 820304, + "samples": [ + 819956, + 819744, + 818944, + 818984, + 820128, + 820176, + 819948, + 820236, + 819880, + 820304 + ] + } + }, + "a01d47f2": { + "phase_ms": { + "median": 666.765, + "p25": 520.278, + "p75": 1156.022, + "min": 450.677, + "max": 1882.249, + "samples": [ + 1001.208, + 1309.911, + 1207.627, + 1882.249, + 747.233, + 544.933, + 512.06, + 450.677, + 466.596, + 586.298 + ] + }, + "total_ms": { + "median": 1141.968, + "p25": 974.723, + "p75": 2326.553, + "min": 922.496, + "max": 3158.114, + "samples": [ + 2374.699, + 2275.18, + 2343.677, + 3158.114, + 1267.594, + 1006.411, + 964.16, + 922.496, + 936.687, + 1016.342 + ] + }, + "cpu_ms": { + "median": 1106.901, + "p25": 973.629, + "p75": 1525.998, + "min": 929.573, + "max": 1568.573, + "samples": [ + 1545.278, + 1568.573, + 1468.158, + 1563.377, + 1196.236, + 1017.565, + 960.219, + 929.573, + 946.096, + 1013.861 + ] + }, + "peak_rss_kib": { + "median": 351564.0, + "p25": 351148.0, + "p75": 352106.0, + "min": 350416, + "max": 353368, + "samples": [ + 351572, + 351268, + 351108, + 350416, + 351656, + 353368, + 352256, + 351556, + 350964, + 352308 + ] + } + }, + "cf837118": { + "phase_ms": { + "median": 505.124, + "p25": 435.315, + "p75": 1103.87, + "min": 417.056, + "max": 1875.147, + "samples": [ + 1875.147, + 1129.722, + 1066.305, + 1116.391, + 461.019, + 423.38, + 417.056, + 445.353, + 549.229, + 431.969 + ] + }, + "total_ms": { + "median": 1209.375, + "p25": 895.862, + "p75": 2133.144, + "min": 872.434, + "max": 2936.234, + "samples": [ + 2936.234, + 2215.538, + 1885.964, + 2695.131, + 1378.495, + 879.351, + 897.968, + 895.16, + 1040.255, + 872.434 + ] + }, + "cpu_ms": { + "median": 1068.41, + "p25": 896.926, + "p75": 1488.578, + "min": 882.398, + "max": 1570.652, + "samples": [ + 1530.601, + 1520.851, + 1391.76, + 1570.652, + 1116.403, + 900.779, + 894.039, + 895.642, + 1020.417, + 882.398 + ] + }, + "peak_rss_kib": { + "median": 273832.0, + "p25": 273592.0, + "p75": 274131.0, + "min": 272732, + "max": 274976, + "samples": [ + 274080, + 272732, + 273560, + 273468, + 274200, + 274148, + 273728, + 273936, + 274976, + 273688 + ] + } + }, + "cd61e11b": { + "phase_ms": { + "median": 429.481, + "p25": 410.043, + "p75": 1178.091, + "min": 399.576, + "max": 1644.881, + "samples": [ + 1194.624, + 1128.491, + 1644.881, + 1428.78, + 405.544, + 434.62, + 424.341, + 414.829, + 408.447, + 399.576 + ] + }, + "total_ms": { + "median": 902.865, + "p25": 868.889, + "p75": 2443.447, + "min": 827.16, + "max": 2961.261, + "samples": [ + 2682.056, + 2199.278, + 2524.837, + 2961.261, + 884.838, + 885.282, + 848.79, + 863.573, + 920.448, + 827.16 + ] + }, + "cpu_ms": { + "median": 920.917, + "p25": 869.777, + "p75": 1475.629, + "min": 840.036, + "max": 1626.459, + "samples": [ + 1518.201, + 1496.456, + 1413.149, + 1626.459, + 893.762, + 899.049, + 861.782, + 861.417, + 942.785, + 840.036 + ] + }, + "peak_rss_kib": { + "median": 267762.0, + "p25": 267612.0, + "p75": 267966.0, + "min": 266300, + "max": 268636, + "samples": [ + 266672, + 268636, + 266300, + 267596, + 267660, + 268280, + 267968, + 267680, + 267960, + 267844 + ] + } + }, + "current": { + "phase_ms": { + "median": 460.489, + "p25": 429.004, + "p75": 986.935, + "min": 404.103, + "max": 1300.033, + "samples": [ + 992.891, + 1126.098, + 1300.033, + 969.067, + 443.604, + 408.397, + 472.429, + 424.137, + 448.549, + 404.103 + ] + }, + "total_ms": { + "median": 935.623, + "p25": 874.18, + "p75": 2282.679, + "min": 839.642, + "max": 2965.198, + "samples": [ + 2320.566, + 2169.019, + 2965.198, + 2531.591, + 924.347, + 839.642, + 946.899, + 873.617, + 875.87, + 854.328 + ] + }, + "cpu_ms": { + "median": 950.702, + "p25": 892.992, + "p75": 1540.918, + "min": 861.669, + "max": 1586.478, + "samples": [ + 1557.765, + 1503.564, + 1553.369, + 1586.478, + 931.391, + 861.669, + 970.013, + 888.14, + 907.549, + 868.73 + ] + }, + "peak_rss_kib": { + "median": 268010.0, + "p25": 267013.0, + "p75": 268385.0, + "min": 266144, + "max": 268876, + "samples": [ + 266824, + 267580, + 266516, + 266144, + 267976, + 268304, + 268044, + 268480, + 268412, + 268876 + ] + }, + "behaviour_json_ms": { + "median": 34.288, + "p25": 23.085, + "p75": 37.474, + "min": 20.137, + "max": 70.397, + "samples": [ + 37.07, + 70.397, + 37.609, + 38.225, + 34.568, + 21.094, + 23.469, + 22.957, + 34.008, + 20.137 + ] + }, + "facts_ms": { + "median": 272.839, + "p25": 256.553, + "p75": 618.472, + "min": 248.146, + "max": 780.388, + "samples": [ + 625.908, + 693.735, + 780.388, + 596.165, + 272.718, + 249.954, + 272.959, + 264.913, + 253.767, + 248.146 + ] + }, + "behaviours_ms": { + "median": 162.633, + "p25": 133.345, + "p75": 326.117, + "min": 132.828, + "max": 476.9, + "samples": [ + 325.198, + 356.28, + 476.9, + 326.424, + 132.828, + 133.946, + 167.929, + 133.144, + 157.337, + 132.934 + ] + }, + "post_rss_kib": { + "median": 268408.0, + "p25": 267369.0, + "p75": 268861.0, + "min": 267052.0, + "max": 269072.0, + "samples": [ + 267084.0, + 268056.0, + 267052.0, + 267140.0, + 268184.0, + 268632.0, + 268660.0, + 269072.0, + 268928.0, + 268960.0 + ] + } + } + } +} diff --git a/benchmarks/shared-json-historical-20261017.json b/benchmarks/shared-json-historical-20261017.json new file mode 100644 index 000000000..2e0e7538f --- /dev/null +++ b/benchmarks/shared-json-historical-20261017.json @@ -0,0 +1,188 @@ +{ + "scope": "Assets + block facts + behaviours loader only; excludes full startup", + "resources": ".local/horizon-client/26.3", + "repeats": 5, + "comparison": "historical cf837118 release binary", + "reference_binary": "target/release/examples/shared_json_startup_profile-cf837118", + "metrics": { + "baseline": { + "phase_ms": { + "median": 1462.003, + "samples": [ + 1639.999, + 1506.864, + 1429.844, + 1462.003, + 1346.061 + ] + }, + "total_ms": { + "median": 1922.795, + "samples": [ + 3383.516, + 1990.554, + 1912.354, + 1922.795, + 1777.912 + ] + }, + "cpu_ms": { + "median": 1961.459, + "samples": [ + 2419.086, + 2021.457, + 1951.587, + 1961.459, + 1839.984 + ] + }, + "peak_rss_kib": { + "median": 820912, + "samples": [ + 819956, + 821052, + 820912, + 821792, + 820424 + ] + } + }, + "pr607": { + "phase_ms": { + "median": 486.715, + "samples": [ + 460.738, + 442.013, + 623.053, + 486.715, + 550.652 + ] + }, + "total_ms": { + "median": 948.089, + "samples": [ + 923.057, + 935.599, + 1109.64, + 948.089, + 1052.546 + ] + }, + "cpu_ms": { + "median": 968.424, + "samples": [ + 928.489, + 946.932, + 1128.431, + 968.424, + 1079.642 + ] + }, + "peak_rss_kib": { + "median": 351796, + "samples": [ + 351796, + 351844, + 351536, + 351532, + 351988 + ] + } + }, + "cf837118": { + "phase_ms": { + "median": 474.268, + "samples": [ + 443.122, + 474.268, + 520.497, + 433.525, + 532.058 + ] + }, + "total_ms": { + "median": 945.87, + "samples": [ + 934.722, + 945.87, + 1006.539, + 888.201, + 1032.6 + ] + }, + "cpu_ms": { + "median": 953.668, + "samples": [ + 941.957, + 953.668, + 1029.122, + 903.574, + 1065.025 + ] + }, + "peak_rss_kib": { + "median": 274476, + "samples": [ + 273448, + 274844, + 274476, + 274556, + 274252 + ] + } + }, + "current": { + "phase_ms": { + "median": 445.924, + "samples": [ + 472.165, + 427.797, + 419.288, + 445.924, + 524.211 + ] + }, + "total_ms": { + "median": 999.669, + "samples": [ + 999.669, + 892.616, + 1051.427, + 940.595, + 1112.158 + ] + }, + "cpu_ms": { + "median": 1001.24, + "samples": [ + 1001.24, + 887.874, + 1051.732, + 951.495, + 1132.208 + ] + }, + "peak_rss_kib": { + "median": 267604, + "samples": [ + 267716, + 267920, + 267448, + 267604, + 267344 + ] + } + } + }, + "builds": { + "current": "release example built at cf837118 + current uncommitted delta in PR #607 worktree", + "historical": "release example built at exact cf837118 commit, with same Cargo release profile and shared dependency target" + }, + "mode_commits": { + "baseline": "independent loader algorithm at e422bd13, executed in current binary", + "pr607": "shared early construction algorithm at a01d47f2, executed in current binary", + "cf837118": "exact historical binary at cf837118, deferred mode", + "current": "current PR worktree, deferred mode with interned strings" + }, + "limitations": "Loader-only (Assets + BlockFacts + Behaviours), no full client startup or first-frame timing. Same release profile but different compilation contexts for historical binary; hardware activity and cache warmth vary. CPU and elapsed differences between cf837118 and current are mixed and may be noise. Peak RSS is whole-process Linux ru_maxrss." +} diff --git a/benchmarks/shared-json-startup-20261017.json b/benchmarks/shared-json-startup-20261017.json new file mode 100644 index 000000000..92f557b33 --- /dev/null +++ b/benchmarks/shared-json-startup-20261017.json @@ -0,0 +1,93 @@ +{ + "scope": "Assets + block facts + behaviours loader only; excludes full startup", + "resources": ".local/horizon-client/26.3", + "repeats": 5, + "metrics": { + "baseline": { + "phase_ms": { + "median": 4730.402, + "samples": [ + 3258.541, + 6539.764, + 4773.735, + 3980.032, + 4730.402 + ] + }, + "total_ms": { + "median": 6325.026, + "samples": [ + 6596.141, + 7627.893, + 6296.443, + 5435.408, + 6325.026 + ] + }, + "cpu_ms": { + "median": 3199.722, + "samples": [ + 3322.801, + 3199.722, + 3227.438, + 3042.687, + 3144.658 + ] + }, + "peak_rss_kib": { + "median": 820000, + "samples": [ + 818540, + 820400, + 819352, + 820000, + 820128 + ] + } + }, + "shared": { + "phase_ms": { + "median": 1180.588, + "samples": [ + 869.228, + 842.213, + 1180.588, + 1560.087, + 1728.575 + ] + }, + "total_ms": { + "median": 2260.709, + "samples": [ + 1632.489, + 1553.753, + 2260.709, + 2879.728, + 3388.639 + ] + }, + "cpu_ms": { + "median": 1603.393, + "samples": [ + 1568.288, + 1432.106, + 1603.393, + 1604.423, + 1619.02 + ] + }, + "peak_rss_kib": { + "median": 351728, + "samples": [ + 353256, + 353664, + 351728, + 350724, + 351668 + ] + } + } + }, + "build": "cargo build --release -p horizon-client --example shared_json_startup_profile", + "limitations": "Loader-only wall-clock timings under concurrent machine load; not full startup or time to first frame. RSS includes Assets::load." +} diff --git a/benchmarks/shared-json-startup-followup-20261017.json b/benchmarks/shared-json-startup-followup-20261017.json new file mode 100644 index 000000000..c828ac7b4 --- /dev/null +++ b/benchmarks/shared-json-startup-followup-20261017.json @@ -0,0 +1,227 @@ +{ + "scope": "Assets + block facts + behaviours loader only; excludes full startup", + "resources": ".local/horizon-client/26.3", + "repeats": 5, + "metrics": { + "baseline": { + "phase_ms": { + "median": 1996.921, + "samples": [ + 2213.335, + 1453.207, + 1637.901, + 1996.921, + 2010.335 + ], + "range": [ + 1453.207, + 2213.335 + ] + }, + "total_ms": { + "median": 4728.136, + "samples": [ + 5628.975, + 2147.329, + 2162.696, + 4728.136, + 6404.524 + ], + "range": [ + 2147.329, + 6404.524 + ] + }, + "cpu_ms": { + "median": 2514.776, + "samples": [ + 2919.908, + 2088.239, + 2212.892, + 2716.104, + 2514.776 + ], + "range": [ + 2088.239, + 2919.908 + ] + }, + "peak_rss_kib": { + "median": 819824, + "samples": [ + 819824, + 820872, + 820744, + 818980, + 818816 + ] + } + }, + "pr607": { + "phase_ms": { + "median": 586.707, + "samples": [ + 464.424, + 739.67, + 586.707, + 1373.307, + 509.266 + ], + "range": [ + 464.424, + 1373.307 + ] + }, + "total_ms": { + "median": 1128.6, + "samples": [ + 954.73, + 1764.614, + 1128.6, + 4312.528, + 1030.735 + ], + "range": [ + 954.73, + 4312.528 + ] + }, + "cpu_ms": { + "median": 1145.826, + "samples": [ + 981.058, + 1465.79, + 1145.826, + 1736.807, + 1056.992 + ], + "range": [ + 981.058, + 1736.807 + ] + }, + "peak_rss_kib": { + "median": 351900, + "samples": [ + 352164, + 351816, + 351900, + 352348, + 350492 + ] + } + }, + "shared": { + "phase_ms": { + "median": 560.117, + "samples": [ + 522.284, + 1255.75, + 560.117, + 2151.064, + 479.329 + ], + "range": [ + 479.329, + 2151.064 + ] + }, + "total_ms": { + "median": 1101.305, + "samples": [ + 1011.715, + 2565.449, + 1101.305, + 2960.186, + 1006.817 + ], + "range": [ + 1006.817, + 2960.186 + ] + }, + "cpu_ms": { + "median": 1128.214, + "samples": [ + 1035.19, + 1565.383, + 1128.214, + 1494.36, + 1031.198 + ], + "range": [ + 1031.198, + 1565.383 + ] + }, + "peak_rss_kib": { + "median": 351532, + "samples": [ + 351624, + 350540, + 351532, + 351716, + 350076 + ] + } + }, + "deferred": { + "phase_ms": { + "median": 564.046, + "samples": [ + 433.35, + 665.149, + 587.456, + 564.046, + 497.422 + ], + "range": [ + 433.35, + 665.149 + ] + }, + "total_ms": { + "median": 1143.129, + "samples": [ + 885.053, + 1143.129, + 1195.869, + 1074.27, + 1162.103 + ], + "range": [ + 885.053, + 1195.869 + ] + }, + "cpu_ms": { + "median": 1114.261, + "samples": [ + 910.946, + 1128.96, + 1194.638, + 1114.261, + 1073.823 + ], + "range": [ + 910.946, + 1194.638 + ] + }, + "peak_rss_kib": { + "median": 273776, + "samples": [ + 274320, + 273860, + 272548, + 273776, + 272520 + ] + } + } + }, + "baseline_commit": "e422bd13", + "pr607_commit": "a01d47f2", + "measurement": "same optimized binary, isolated processes in alternating forward/reverse four-mode runs", + "limitations": "Includes Assets::load, BlockFacts, Behaviours; excludes complete client startup, pack/mod root resolution, graphics and first frame. Different modes emulate the original independent, PR #607 at a01d47f2, paired and deferred startup sequences in the same release build. Machine was not idle. Elapsed times show high variance; no statistically established gain between PR, paired and deferred modes." +} diff --git a/benchmarks/shared-json-variant-isolation-20261017.json b/benchmarks/shared-json-variant-isolation-20261017.json new file mode 100644 index 000000000..e399c7ba1 --- /dev/null +++ b/benchmarks/shared-json-variant-isolation-20261017.json @@ -0,0 +1,453 @@ +{ + "scope": "Assets + BlockFacts + Behaviours loader only; no full startup or first frame", + "resources": "/srv/bob-data/horizon/.local/horizon-client/26.3", + "repeats": 8, + "ordering": [ + [ + "cf837118", + "cd61e11b", + "arc-key", + "reused-sounds", + "current" + ], + [ + "current", + "reused-sounds", + "arc-key", + "cd61e11b", + "cf837118" + ], + [ + "cf837118", + "cd61e11b", + "arc-key", + "reused-sounds", + "current" + ], + [ + "current", + "reused-sounds", + "arc-key", + "cd61e11b", + "cf837118" + ], + [ + "cf837118", + "cd61e11b", + "arc-key", + "reused-sounds", + "current" + ], + [ + "current", + "reused-sounds", + "arc-key", + "cd61e11b", + "cf837118" + ], + [ + "cf837118", + "cd61e11b", + "arc-key", + "reused-sounds", + "current" + ], + [ + "current", + "reused-sounds", + "arc-key", + "cd61e11b", + "cf837118" + ] + ], + "load_average_before": [ + 10.9873046875, + 8.37646484375, + 6.91015625 + ], + "load_average_after": [ + 8.6962890625, + 8.1591796875, + 6.90087890625 + ], + "executables": { + "cf837118": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-cf837118", + "mode": "deferred", + "sha256": "f1b044cd9ac2f67c644fb40bd7ecbe38128ec739a8112d57fc36f05fe9036a52" + }, + "cd61e11b": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-cd61e11b", + "mode": "deferred", + "sha256": "fb2d3725b09ee38f85b49901f7053a6fe339b980a2b2dac6930a8ded22c139e8" + }, + "arc-key": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-arcpool", + "mode": "deferred", + "sha256": "8cbb53d01afedf5c7a5da0e36c9f8c3569f34def9bc51488fe8699e7f615a131" + }, + "reused-sounds": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-reusesounds", + "mode": "deferred", + "sha256": "f45794bfbdbb3f9b5d34c375d397191ac67984b3ae91268aa3fdd02f2c1b7b98" + }, + "current": { + "path": "/srv/bob-data/horizon/.worktrees/shared-block-json-20261017/target/release/examples/shared_json_startup_profile-new", + "mode": "deferred", + "sha256": "84eb1baae8e138f52e300b0b44f1339fca38e70db6e06126e78db776ea3e5cd0" + } + }, + "metrics": { + "cf837118": { + "phase_ms": { + "median": 424.082, + "p25": 417.508, + "p75": 430.923, + "min": 395.439, + "max": 948.609, + "samples": [ + 948.609, + 425.085, + 425.571, + 417.945, + 395.439, + 416.197, + 423.078, + 446.98 + ] + }, + "total_ms": { + "median": 853.026, + "p25": 839.421, + "p75": 867.731, + "min": 813.144, + "max": 1906.081, + "samples": [ + 1906.081, + 861.641, + 864.233, + 844.411, + 813.144, + 830.783, + 842.3, + 878.226 + ] + }, + "cpu_ms": { + "median": 876.143, + "p25": 862.934, + "p75": 891.4, + "min": 837.769, + "max": 1517.372, + "samples": [ + 1517.372, + 885.13, + 887.888, + 865.404, + 837.769, + 855.526, + 867.157, + 901.937 + ] + }, + "peak_rss_kib": { + "median": 273904.0, + "p25": 273717.0, + "p75": 274142.0, + "min": 273648, + "max": 274836, + "samples": [ + 273648, + 273936, + 273872, + 274836, + 274064, + 274376, + 273740, + 273648 + ] + } + }, + "cd61e11b": { + "phase_ms": { + "median": 422.356, + "p25": 406.294, + "p75": 425.846, + "min": 394.111, + "max": 472.536, + "samples": [ + 425.832, + 420.666, + 472.536, + 425.886, + 400.588, + 394.111, + 424.047, + 408.196 + ] + }, + "total_ms": { + "median": 852.475, + "p25": 828.474, + "p75": 876.413, + "min": 817.3, + "max": 951.587, + "samples": [ + 951.587, + 865.442, + 899.564, + 868.696, + 823.74, + 817.3, + 839.508, + 830.052 + ] + }, + "cpu_ms": { + "median": 875.04, + "p25": 850.012, + "p75": 900.57, + "min": 837.672, + "max": 938.285, + "samples": [ + 938.285, + 888.533, + 926.846, + 891.812, + 845.956, + 837.672, + 861.548, + 851.364 + ] + }, + "peak_rss_kib": { + "median": 268086.0, + "p25": 267719.0, + "p75": 268486.0, + "min": 267444, + "max": 268920, + "samples": [ + 267776, + 268660, + 267752, + 268920, + 268428, + 268396, + 267444, + 267620 + ] + } + }, + "arc-key": { + "phase_ms": { + "median": 421.422, + "p25": 401.781, + "p75": 451.774, + "min": 394.041, + "max": 472.337, + "samples": [ + 446.155, + 472.337, + 468.632, + 420.636, + 400.91, + 394.041, + 422.207, + 402.072 + ] + }, + "total_ms": { + "median": 866.601, + "p25": 822.563, + "p75": 918.038, + "min": 817.092, + "max": 1001.287, + "samples": [ + 1001.287, + 918.457, + 917.898, + 892.666, + 817.092, + 824.225, + 840.536, + 817.576 + ] + }, + "cpu_ms": { + "median": 887.84, + "p25": 844.533, + "p75": 937.331, + "min": 838.687, + "max": 991.212, + "samples": [ + 991.212, + 949.048, + 933.425, + 911.921, + 838.687, + 845.021, + 863.759, + 843.069 + ] + }, + "peak_rss_kib": { + "median": 267728.0, + "p25": 267598.0, + "p75": 268039.0, + "min": 267452, + "max": 268636, + "samples": [ + 268264, + 267616, + 267840, + 267964, + 268636, + 267452, + 267580, + 267604 + ] + } + }, + "reused-sounds": { + "phase_ms": { + "median": 421.683, + "p25": 412.913, + "p75": 439.098, + "min": 395.338, + "max": 487.446, + "samples": [ + 487.446, + 434.111, + 402.815, + 416.279, + 424.524, + 454.058, + 395.338, + 418.842 + ] + }, + "total_ms": { + "median": 879.846, + "p25": 845.021, + "p75": 901.166, + "min": 823.721, + "max": 1013.539, + "samples": [ + 1013.539, + 892.033, + 928.565, + 884.284, + 847.853, + 875.407, + 823.721, + 836.527 + ] + }, + "cpu_ms": { + "median": 894.546, + "p25": 871.499, + "p75": 921.844, + "min": 844.891, + "max": 1028.688, + "samples": [ + 1028.688, + 913.48, + 946.935, + 903.785, + 868.684, + 885.308, + 844.891, + 872.438 + ] + }, + "peak_rss_kib": { + "median": 267960.0, + "p25": 267678.0, + "p75": 268133.0, + "min": 267212, + "max": 268404, + "samples": [ + 267212, + 267888, + 268404, + 267692, + 268096, + 267636, + 268244, + 268032 + ] + } + }, + "current": { + "phase_ms": { + "median": 411.403, + "p25": 406.814, + "p75": 452.869, + "min": 391.768, + "max": 532.402, + "samples": [ + 532.402, + 442.563, + 408.857, + 410.202, + 483.788, + 391.768, + 400.683, + 412.604 + ] + }, + "total_ms": { + "median": 905.017, + "p25": 851.488, + "p75": 937.934, + "min": 818.206, + "max": 1075.445, + "samples": [ + 1075.445, + 878.155, + 837.627, + 955.655, + 932.027, + 818.206, + 856.108, + 931.88 + ] + }, + "cpu_ms": { + "median": 922.9, + "p25": 874.849, + "p75": 956.282, + "min": 839.639, + "max": 1067.693, + "samples": [ + 1067.693, + 900.18, + 862.137, + 970.356, + 951.591, + 839.639, + 879.086, + 945.62 + ] + }, + "peak_rss_kib": { + "median": 268354.0, + "p25": 267889.0, + "p75": 268492.0, + "min": 267056, + "max": 268820, + "samples": [ + 268008, + 268384, + 268564, + 268820, + 267056, + 267532, + 268324, + 268468 + ] + } + } + }, + "experiment_note": "Exploratory variants (Arc-key pool, reused sounds, combined proposal) alongside cd61e11b; none gave a robust consistent improvement and all were reverted." +} diff --git a/crates/horizon-client/examples/gameplay_decode_profile.rs b/crates/horizon-client/examples/gameplay_decode_profile.rs new file mode 100644 index 000000000..60260452f --- /dev/null +++ b/crates/horizon-client/examples/gameplay_decode_profile.rs @@ -0,0 +1,33 @@ +//! Profile the two mandatory passes over gameplay-facts.json independently. +//! Build with `cargo build --release -p horizon-client --example gameplay_decode_profile`. +//! Each invocation runs one phase in a separate process for CPU/RSS measurements. +#[allow(dead_code)] +#[path = "../src/blocks/decode.rs"] +mod decode; + +use std::{hint::black_box, path::Path, time::Instant}; + +// The included private decoder expects the parent crate Result alias. +type Result = std::result::Result>; + +fn main() -> Result<()> { + let mut args = std::env::args().skip(1); + let root = args.next().ok_or("expected resource directory")?; + let mode = args.next().ok_or("expected validate or typed")?; + if mode != "validate" && mode != "typed" { + return Err("expected validate or typed".into()); + } + let total = Instant::now(); + let bytes = std::fs::read(Path::new(&root).join("gameplay-facts.json"))?; + let started = Instant::now(); + if mode == "validate" { + let parsed: decode::Validate = serde_json::from_slice(&bytes)?; + black_box(parsed); + } else { + let parsed: decode::Gameplay<'_> = serde_json::from_slice(&bytes)?; + black_box(parsed); + } + println!("phase_ms={:.3}", started.elapsed().as_secs_f64() * 1000.0); + println!("total_ms={:.3}", total.elapsed().as_secs_f64() * 1000.0); + Ok(()) +} diff --git a/crates/horizon-client/examples/shared_json_startup_profile.rs b/crates/horizon-client/examples/shared_json_startup_profile.rs new file mode 100644 index 000000000..7b7d896b2 --- /dev/null +++ b/crates/horizon-client/examples/shared_json_startup_profile.rs @@ -0,0 +1,74 @@ +//! Profile the fact and behaviour table phase of client startup. +//! Run each mode in a separate process to capture CPU usage and peak RSS. +//! The deferred mode evaluates both phases contiguously for fair loader comparison; +//! actual client startup performs other initialization between these phases. +use horizon_client::{assets::Assets, blocks::BlockFacts}; +use horizon_world::level::Behaviours; +use std::{path::Path, time::Instant}; + +fn resident_kib() -> Option { + let status = std::fs::read_to_string("/proc/self/status").ok()?; + let line = status.lines().find(|line| line.starts_with("VmRSS:"))?; + line.split_whitespace().nth(1)?.parse().ok() +} + +fn main() -> Result<(), Box> { + let mut args = std::env::args().skip(1); + let root = args.next().ok_or("expected resource directory")?; + let mode = args + .next() + .ok_or("expected baseline, pr607, shared, deferred or deferred-held")?; + if !["baseline", "pr607", "shared", "deferred", "deferred-held"].contains(&mode.as_str()) { + return Err("expected baseline, pr607, shared, deferred or deferred-held".into()); + } + let root = Path::new(&root); + let total = Instant::now(); + let assets = Assets::load(root)?; + let started = Instant::now(); + let mut retained_inputs = None; + let mut subphases = None; + let (facts, behaviours) = if mode == "baseline" { + ( + BlockFacts::load(root, assets.registry)?, + Behaviours::load(assets.registry, root)?, + ) + } else if mode == "pr607" { + // Original PR #607 sequence at a01d47f2, retained as a same-build comparator. + let json: serde_json::Value = serde_json::from_reader(std::io::BufReader::new( + std::fs::File::open(root.join("block-behaviours.json"))?, + ))?; + BlockFacts::load_with_behaviours(root, assets.registry, &json)? + } else if mode == "shared" { + BlockFacts::load_pair(root, assets.registry)? + } else { + let parse_started = Instant::now(); + let json: serde_json::Value = serde_json::from_reader(std::io::BufReader::new( + std::fs::File::open(root.join("block-behaviours.json"))?, + ))?; + let parse_ms = parse_started.elapsed().as_secs_f64() * 1000.0; + let facts_started = Instant::now(); + let (facts, gameplay) = BlockFacts::load_with_projection(root, assets.registry, &json)?; + let facts_ms = facts_started.elapsed().as_secs_f64() * 1000.0; + let behaviours_started = Instant::now(); + let behaviours = Behaviours::load_with_gameplay(assets.registry, root, &json, &gameplay)?; + let behaviours_ms = behaviours_started.elapsed().as_secs_f64() * 1000.0; + subphases = Some((parse_ms, facts_ms, behaviours_ms)); + if mode == "deferred-held" { + retained_inputs = Some((json, gameplay)); + } + (facts, behaviours) + }; + println!("phase_ms={:.3}", started.elapsed().as_secs_f64() * 1000.0); + println!("total_ms={:.3}", total.elapsed().as_secs_f64() * 1000.0); + println!("states={}", facts.states.len()); + if let Some((parse, facts, behaviours)) = subphases { + println!("behaviour_json_ms={parse:.3}"); + println!("facts_ms={facts:.3}"); + println!("behaviours_ms={behaviours:.3}"); + } + if let Some(rss) = resident_kib() { + println!("post_rss_kib={rss}"); + } + std::hint::black_box((facts, behaviours, retained_inputs)); + Ok(()) +} diff --git a/crates/horizon-client/examples/translucency_fixture.rs b/crates/horizon-client/examples/translucency_fixture.rs new file mode 100644 index 000000000..11083d6b2 --- /dev/null +++ b/crates/horizon-client/examples/translucency_fixture.rs @@ -0,0 +1,47 @@ +//! Transport for the vanilla quad sorting / viewpoint parity gate. +use horizon_client::gfx::translucency::{SortState, Sorter, quad_center}; +use serde::Deserialize; +use serde_json::json; +use std::{ + fs, + io::{BufWriter, Write}, +}; + +#[derive(Deserialize)] +struct Case { + origin: [i32; 3], + quads: Vec<[[f32; 3]; 4]>, + cameras: Vec<[f64; 3]>, +} + +fn main() -> Result<(), Box> { + let args: Vec<_> = std::env::args().skip(1).collect(); + let [input, output] = args.as_slice() else { + return Err("usage: translucency_fixture INPUT OUTPUT".into()); + }; + let mut out = BufWriter::new(fs::File::create(output)?); + for line in fs::read_to_string(input)?.lines() { + let case: Case = serde_json::from_str(line)?; + let centers: Vec<_> = case.quads.iter().map(|q| quad_center(q[0], q[2])).collect(); + let mut state = SortState::new(centers.clone()); + let mut sorter = Sorter::default(); + let mut cache_sorter = Sorter::default(); + let frames: Vec<_> = case + .cameras + .iter() + .map(|&camera| { + let update = state + .update(camera, case.origin, &mut cache_sorter) + .is_some(); + let local = std::array::from_fn(|i| (camera[i] - f64::from(case.origin[i])) as f32); + json!({"indices": sorter.sort(¢ers, local), "update": update}) + }) + .collect(); + let bits: Vec<_> = centers + .iter() + .map(|c| c.map(|f| f.to_bits() as i32)) + .collect(); + writeln!(out, "{}", json!({"centers": bits, "frames": frames}))?; + } + Ok(()) +} diff --git a/crates/horizon-client/examples/world_options_fixture.rs b/crates/horizon-client/examples/world_options_fixture.rs new file mode 100644 index 000000000..5bbf9f1c7 --- /dev/null +++ b/crates/horizon-client/examples/world_options_fixture.rs @@ -0,0 +1,40 @@ +//! Packet payload oracle companion for tools/test_world_options_parity.py. +use horizon_protocol::{buf::Reader, packets::play::*}; +use std::{error::Error, fmt::Write}; + +fn main() -> Result<(), Box> { + let args: Vec = std::env::args().collect(); + let mut output = String::new(); + for line in std::fs::read_to_string(&args[1])?.lines() { + let fields: Vec<&str> = line.split('\t').collect(); + let entries = if fields.len() == 3 { + vec![GameRuleEntry { + name: format!("minecraft:{}", fields[1]), + value: fields[2].into(), + }] + } else { + vec![] + }; + let bytes = match fields[0] { + "difficulty" => Serverbound::ChangeDifficulty(ChangeDifficultyRequest { + difficulty: fields[1].parse()?, + }) + .encode(), + "lock" => Serverbound::LockDifficulty(LockDifficulty { + locked: fields[1].parse()?, + }) + .encode(), + "set" => Serverbound::SetGameRule(SetGameRule { entries }).encode(), + "values" => Clientbound::GameRuleValues(GameRuleValues { entries }).encode(), + _ => return Err("unknown case".into()), + }; + let mut reader = Reader::new(&bytes); + reader.varint()?; + for byte in reader.rest() { + write!(output, "{byte:02x}")?; + } + output.push('\n'); + } + std::fs::write(&args[2], output)?; + Ok(()) +} diff --git a/crates/horizon-client/src/block_entity_render.rs b/crates/horizon-client/src/block_entity_render.rs index 85107c1cb..9c90e8ebf 100644 --- a/crates/horizon-client/src/block_entity_render.rs +++ b/crates/horizon-client/src/block_entity_render.rs @@ -898,15 +898,9 @@ impl BlockEntityRenderer { pub fn renders(&self, state: u32) -> bool { !matches!(self.kind(state), Kind::None) } - /// BannerRenderer submits the support and animated flag once for crumbling. - pub fn render_banner_breaking( - &self, - scene: &Scene, - pos: [i32; 3], - state: u32, - out: &mut Vec, - ) { - if !matches!(self.kind(state), Kind::Banner { .. }) { + /// ChestRenderer and BannerRenderer submit their animated models for crumbling. + pub fn render_breaking(&self, scene: &Scene, pos: [i32; 3], state: u32, out: &mut Vec) { + if !matches!(self.kind(state), Kind::Banner { .. } | Kind::Chest { .. }) { return; } let origin = (DVec3::new(f64::from(pos[0]), f64::from(pos[1]), f64::from(pos[2])) @@ -1098,7 +1092,7 @@ impl BlockEntityRenderer { ChestPart::Left => "double_chest_left", ChestPart::Right => "double_chest_right", }; - let (Some(model), Some(_)) = (self.models.get(model), sprite(texture)) else { + let Some(model) = self.models.get(model) else { return; }; let (open, other) = self.chest_openness( @@ -1719,18 +1713,28 @@ mod tests { use super::*; #[test] #[ignore = "requires prepared models/textures in HORIZON_TEST_RESOURCES"] - fn banner_particle_and_breaking_use_exported_models() -> crate::Result<()> { + fn entity_block_particles_and_breaking_use_exported_models() -> crate::Result<()> { use crate::{models::catalog::StateModels, sprites::Sprites}; use horizon_world::{DATA_VERSION, chunk::BlockState, nbt::Tag}; let root = std::path::PathBuf::from( std::env::var_os("HORIZON_TEST_RESOURCES").expect("HORIZON_TEST_RESOURCES"), ); - let names = ["white_banner", "white_wall_banner"]; + let names = [ + "white_banner", + "white_wall_banner", + "chest", + "trapped_chest", + "ender_chest", + "copper_chest", + ]; let mut facts: std::collections::BTreeMap = serde_json::from_slice(&std::fs::read(root.join("model-states.json"))?)?; let states = names.map(|name| { let name = format!("minecraft:{name}"); - let first = facts[&name]["states"][0].clone(); + let mut first = facts[&name]["states"][0].clone(); + if first.get("type").is_some() { + first["type"] = serde_json::json!("single"); + } facts.get_mut(&name).unwrap()["states"] = serde_json::json!([first.clone()]); BlockState { name, @@ -1743,24 +1747,28 @@ mod tests { ("states", Tag::List(states.into())), ( "defaults", - Tag::compound([ - ("minecraft:white_banner", Tag::Int(0)), - ("minecraft:white_wall_banner", Tag::Int(1)), - ]), + Tag::compound(names.iter().enumerate().map(|(id, name)| { + ( + horizon_world::nbt::JavaString::from(format!("minecraft:{name}").as_str()), + Tag::Int(id as i32), + ) + })), ), ]))?; let mut sprites = Sprites::default(); let catalog = StateModels::from_facts(&root, ®istry, &names, &mut sprites, &facts)?; - for id in 0..2 { + for (id, name) in names.iter().enumerate() { let models = catalog.collect( - BlockStateId(id), + BlockStateId(id as u32), horizon_core::position::BlockPos::default(), )?; assert!(models.iter().all(|(_, model)| model.faces.is_empty())); - assert_eq!( - models[0].1.particle, - Some(sprites.layers["minecraft:block/oak_planks"]) - ); + let particle = match *name { + "ender_chest" => "minecraft:block/obsidian", + "copper_chest" => "minecraft:block/copper_block", + _ => "minecraft:block/oak_planks", + }; + assert_eq!(models[0].1.particle, Some(sprites.layers[particle])); } let all: Value = serde_json::from_slice(&std::fs::read(root.join("entity-models.json"))?)?; let renderer = BlockEntityRenderer::new( @@ -1771,17 +1779,28 @@ mod tests { ®istry, ); let world = World::new(BlockStateId(0), 1); - let base_sprites = HashMap::from([( - "entity/banner/banner_base".to_owned(), - Rect { - u0: 0.0, - v0: 0.0, - u1: 1.0, - v1: 1.0, - w: 16, - h: 16, - }, - )]); + let base_sprites = [ + "entity/banner/banner_base", + "entity/chest/normal", + "entity/chest/trapped", + "entity/chest/ender", + "entity/chest/copper", + ] + .into_iter() + .map(|name| { + ( + name.to_owned(), + Rect { + u0: 0.0, + v0: 0.0, + u1: 1.0, + v1: 1.0, + w: 16, + h: 16, + }, + ) + }) + .collect(); let mut scene = Scene { camera: DVec3::ZERO, orientation: Quat::IDENTITY, @@ -1798,11 +1817,11 @@ mod tests { banner: &|_| Vec::new(), glyph: &|_| (None, 0.0), }; - for state in 0..2 { + for state in 0..names.len() as u32 { let mut base = Vec::new(); renderer.render_block(&scene, [0; 3], state, Mat4::IDENTITY, 0xff, &mut base); let mut cracks = Vec::new(); - renderer.render_banner_breaking(&scene, [0; 3], state, &mut cracks); + renderer.render_breaking(&scene, [0; 3], state, &mut cracks); assert!(!cracks.is_empty()); assert_eq!( base.iter().map(|v| v.pos).collect::>(), @@ -1812,10 +1831,14 @@ mod tests { && v.color == u32::MAX && v.uv.iter().all(|u| u.is_finite()))); scene.game_time = 20; + if state >= 2 { + scene.lid = &|_| 1.0; + } let mut animated = Vec::new(); - renderer.render_banner_breaking(&scene, [0; 3], state, &mut animated); + renderer.render_breaking(&scene, [0; 3], state, &mut animated); assert!(cracks.iter().zip(&animated).any(|(a, b)| a.pos != b.pos)); scene.game_time = 0; + scene.lid = &|_| 0.0; } Ok(()) } diff --git a/crates/horizon-client/src/blocks.rs b/crates/horizon-client/src/blocks.rs index 521d389bc..27a36396a 100644 --- a/crates/horizon-client/src/blocks.rs +++ b/crates/horizon-client/src/blocks.rs @@ -2,7 +2,10 @@ //! (`gameplay-facts.json`), indexed by registry state ID. mod decode; use crate::Result; -use horizon_world::registry::{BlockRegistry, BlockStateId}; +use horizon_world::{ + level::{Behaviours, GameplayStateSource}, + registry::{BlockRegistry, BlockStateId}, +}; use serde_json::Value; use std::{ collections::HashMap, @@ -107,12 +110,178 @@ impl StateFacts { self.classes.iter().any(|c| &**c == name) } } +/// Compact, owned behaviour inputs retained until the normal behaviour startup stage. +/// No borrowed gameplay JSON or process-wide cache survives the fact loader. +pub struct GameplayProjection { + flags: u16, + emission: u64, + dampening: u64, + hardness: f64, + push: Arc, + volume: f64, + pitch: f64, + place: Arc, + break_sound: Arc, + fall: Arc, +} + +impl GameplayProjection { + fn from_entry(entry: &decode::Entry<'_>, strings: &mut HashMap>) -> Self { + fn intern(strings: &mut HashMap>, value: &str) -> Arc { + if let Some(existing) = strings.get(value) { + return Arc::clone(existing); + } + let value_arc: Arc = Arc::from(value); + strings.insert(value.to_owned(), Arc::clone(&value_arc)); + value_arc + } + const FLAGS: [&str; 11] = [ + "replaceable", + "random_ticks", + "solid_render", + "liquid", + "block_entity", + "ignited_by_lava", + "can_occlude", + "full_collision", + "skylight_down", + "requires_tool", + "shape_occlusion", + ]; + Self { + flags: FLAGS.iter().enumerate().fold(0, |flags, (i, name)| { + flags | ((u16::from(entry.flag(name))) << i) + }), + emission: entry.unsigned("emission"), + dampening: entry.unsigned("dampening"), + hardness: entry.number("hardness"), + push: intern(strings, entry.text("push")), + volume: entry.sound_number("volume"), + pitch: entry.sound_number("pitch"), + place: intern(strings, entry.sound_id("place")), + break_sound: intern(strings, entry.sound_id("break")), + fall: intern(strings, entry.sound_id("fall")), + } + } +} + +impl GameplayStateSource for GameplayProjection { + fn flag(&self, name: &str) -> bool { + const FLAGS: [&str; 11] = [ + "replaceable", + "random_ticks", + "solid_render", + "liquid", + "block_entity", + "ignited_by_lava", + "can_occlude", + "full_collision", + "skylight_down", + "requires_tool", + "shape_occlusion", + ]; + FLAGS + .iter() + .position(|field| *field == name) + .is_some_and(|index| self.flags & (1 << index) != 0) + } + fn unsigned(&self, name: &str) -> u64 { + match name { + "emission" => self.emission, + "dampening" => self.dampening, + _ => 0, + } + } + fn number(&self, name: &str) -> f64 { + if name == "hardness" { + self.hardness + } else { + 0.0 + } + } + fn text(&self, name: &str) -> &str { + if name == "push" { &self.push } else { "" } + } + fn sound_number(&self, name: &str) -> f64 { + match name { + "volume" => self.volume, + "pitch" => self.pitch, + _ => 1.0, + } + } + fn sound_id(&self, name: &str) -> &str { + match name { + "place" => &self.place, + "break" => &self.break_sound, + "fall" => &self.fall, + _ => "", + } + } +} + pub struct BlockFacts { pub states: Vec, pub air: BlockStateId, } impl BlockFacts { pub fn load(root: &Path, registry: &BlockRegistry) -> Result { + let behaviours: Value = serde_json::from_reader(BufReader::new(File::open( + root.join("block-behaviours.json"), + )?))?; + Self::load_with_behaviour_json(root, registry, &behaviours) + } + + /// Load both tables from one resource root, sharing each JSON decode. + /// No data is cached across calls: changes to prepared packs or mods are read again. + pub fn load_pair(root: &Path, registry: &BlockRegistry) -> Result<(Self, Behaviours)> { + let behaviours: Value = serde_json::from_reader(BufReader::new(File::open( + root.join("block-behaviours.json"), + )?))?; + Self::load_with_behaviours(root, registry, &behaviours) + } + + /// Decode state facts once, retaining only the small owned fields needed later. + pub fn load_with_projection( + root: &Path, + registry: &BlockRegistry, + behaviours: &Value, + ) -> Result<(Self, Vec)> { + Self::load_with_callback(root, registry, behaviours, |entries| { + let mut strings = HashMap::new(); + Ok(entries + .iter() + .map(|entry| GameplayProjection::from_entry(entry, &mut strings)) + .collect()) + }) + } + + pub fn load_with_behaviour_json( + root: &Path, + registry: &BlockRegistry, + behaviours: &Value, + ) -> Result { + Ok(Self::load_with_callback(root, registry, behaviours, |_| Ok(()))?.0) + } + + /// Build both tables from the same behaviour document and gameplay decoder. + pub fn load_with_behaviours( + root: &Path, + registry: &BlockRegistry, + behaviours: &Value, + ) -> Result<(Self, Behaviours)> { + Self::load_with_callback(root, registry, behaviours, |entries| { + Ok(Behaviours::load_with_gameplay( + registry, root, behaviours, entries, + )?) + }) + } + + fn load_with_callback( + root: &Path, + registry: &BlockRegistry, + behaviours: &Value, + callback: impl FnOnce(&[decode::Entry<'_>]) -> Result, + ) -> Result<(Self, T)> { let bytes = fs::read(root.join("gameplay-facts.json"))?; serde_json::from_slice::(&bytes)?; let raw: decode::Gameplay<'_> = serde_json::from_slice(&bytes)?; @@ -125,9 +294,6 @@ impl BlockFacts { return Err("gameplay facts do not match the block registry".into()); } // Class chains and per-state behaviour flags exported from the actual block objects. - let behaviours: Value = serde_json::from_reader(BufReader::new(File::open( - root.join("block-behaviours.json"), - )?))?; let behaviour_states = behaviours["states"] .as_array() .filter(|s| s.len() == registry.len()) @@ -221,13 +387,13 @@ impl BlockFacts { outline, outline_edges, name: intern(&state.name), - emission: entry.emission as u8, - dampening: entry.dampening as u8, + emission: entry.emission.as_f64().unwrap_or(0.0) as u8, + dampening: entry.dampening.as_f64().unwrap_or(0.0) as u8, skylight_down: entry.skylight_down, shape_occlusion: entry.shape_occlusion, can_occlude: entry.can_occlude, solid_render: entry.solid_render, - hardness: entry.hardness as f32, + hardness: entry.hardness.as_f64().unwrap_or(0.0) as f32, requires_tool: entry.requires_tool, replaceable: entry.replaceable, random_ticks: entry.random_ticks, @@ -264,12 +430,16 @@ impl BlockFacts { .ok_or("missing block behaviour class chain")?, }); } - Ok(Self { - states, - air: registry - .default_state("minecraft:air") - .ok_or("missing air")?, - }) + let extra = callback(entries)?; + Ok(( + Self { + states, + air: registry + .default_state("minecraft:air") + .ok_or("missing air")?, + }, + extra, + )) } pub fn get(&self, id: BlockStateId) -> &StateFacts { &self.states[id.0 as usize] @@ -281,3 +451,56 @@ impl BlockFacts { ) } } + +impl GameplayStateSource for decode::Entry<'_> { + fn flag(&self, name: &str) -> bool { + match name { + "replaceable" => self.replaceable, + "random_ticks" => self.random_ticks, + "solid_render" => self.solid_render, + "liquid" => self.liquid, + "block_entity" => self.block_entity, + "ignited_by_lava" => self.ignited_by_lava, + "can_occlude" => self.can_occlude, + "full_collision" => self.full_collision, + "skylight_down" => self.skylight_down, + "requires_tool" => self.requires_tool, + "shape_occlusion" => self.shape_occlusion, + _ => false, + } + } + fn unsigned(&self, name: &str) -> u64 { + match name { + "emission" => self.emission.as_u64().unwrap_or(0), + "dampening" => self.dampening.as_u64().unwrap_or(0), + _ => 0, + } + } + fn number(&self, name: &str) -> f64 { + match name { + "hardness" => self.hardness.as_f64().unwrap_or(0.0), + _ => 0.0, + } + } + fn text(&self, name: &str) -> &str { + match name { + "push" => self.push.as_deref().unwrap_or(""), + _ => "", + } + } + fn sound_number(&self, name: &str) -> f64 { + match name { + "volume" => self.sound.volume, + "pitch" => self.sound.pitch, + _ => 1.0, + } + } + fn sound_id(&self, name: &str) -> &str { + match name { + "place" => self.sound.place.id.as_deref().unwrap_or(""), + "break" => self.sound.r#break.id.as_deref().unwrap_or(""), + "fall" => self.sound.fall.id.as_deref().unwrap_or(""), + _ => "", + } + } +} diff --git a/crates/horizon-client/src/blocks/decode.rs b/crates/horizon-client/src/blocks/decode.rs index 967955f9e..7feb3ac41 100644 --- a/crates/horizon-client/src/blocks/decode.rs +++ b/crates/horizon-client/src/blocks/decode.rs @@ -155,17 +155,20 @@ object!(Sound<'a> { }); object!(Entry<'a> { id: Option = None => value(unsigned), - emission: f64 = 0.0 => value(number), - dampening: f64 = 0.0 => value(number), + emission: Value = Value::Null => typed, + dampening: Value = Value::Null => typed, skylight_down: bool = false => value(flag), shape_occlusion: bool = false => value(flag), can_occlude: bool = false => value(flag), solid_render: bool = false => value(flag), - hardness: f64 = 0.0 => value(number), + hardness: Value = Value::Null => typed, requires_tool: bool = false => value(flag), replaceable: bool = false => value(flag), random_ticks: bool = false => value(flag), block_entity: bool = false => value(flag), + liquid: bool = false => value(flag), + ignited_by_lava: bool = false => value(flag), + push: Option = None => value(text), render_shape: Option = None => value(text), full_collision: bool = false => value(flag), friction: f64 = 0.0 => value(number), diff --git a/crates/horizon-client/src/blocks/decode_tests.rs b/crates/horizon-client/src/blocks/decode_tests.rs index d9d0e14fd..8fdb93f4f 100644 --- a/crates/horizon-client/src/blocks/decode_tests.rs +++ b/crates/horizon-client/src/blocks/decode_tests.rs @@ -89,9 +89,9 @@ fn typed_fields_keep_defaults_duplicates_and_wrong_type_behavior() -> crate::Res assert_eq!(entries[1].id, None); let e = &entries[2]; assert_eq!(e.id, Some(2)); - assert_eq!(e.emission, 4.5); - assert_eq!(e.dampening, 0.0); - assert_eq!(e.hardness.to_bits(), (-0.0f64).to_bits()); + assert_eq!(e.emission.as_f64(), Some(4.5)); + assert_eq!(e.dampening.as_f64().unwrap_or(0.0), 0.0); + assert_eq!(e.hardness.as_f64().unwrap().to_bits(), (-0.0f64).to_bits()); assert!(e.skylight_down && e.outline_offset.unwrap_or(e.offset)); assert_eq!(e.item, None); assert_eq!(e.render_shape, None); diff --git a/crates/horizon-client/src/entities.rs b/crates/horizon-client/src/entities.rs index a1e18076e..5e6a3336a 100644 --- a/crates/horizon-client/src/entities.rs +++ b/crates/horizon-client/src/entities.rs @@ -301,6 +301,20 @@ pub struct Experience { pub total: i32, } impl Experience { + /// `Player.getBaseExperienceReward`: keep-inventory and spectators drop none. + pub fn death_reward(&self, keep: bool) -> u32 { + if keep { + 0 + } else { + self.level.wrapping_mul(7).clamp(0, 100) as u32 + } + } + /// `ServerPlayer.restoreFrom`: only keep-inventory and spectators retain XP. + pub fn respawn(&mut self, keep: bool) { + if !keep { + *self = Self::default(); + } + } pub fn needed(level: i32) -> i32 { if level >= 30 { 112 + (level - 30) * 9 @@ -540,6 +554,37 @@ impl ArmorStand { } } +#[cfg(test)] +mod experience_tests { + use super::*; + + #[test] + fn death_reward_uses_levels_and_caps_the_recoverable_points() { + for (level, reward) in [(0, 0), (1, 7), (14, 98), (15, 100), (30, 100)] { + let xp = Experience { + level, + progress: 0.75, + total: 10_000, + }; + assert_eq!(xp.death_reward(false), reward); + assert_eq!(xp.death_reward(true), 0); + } + } + + #[test] + fn respawn_clears_all_xp_unless_it_is_kept() { + let mut xp = Experience::default(); + xp.give(155); + let before = (xp.level, xp.progress, xp.total); + xp.respawn(true); + assert_eq!((xp.level, xp.progress, xp.total), before); + xp.respawn(false); + assert_eq!((xp.level, xp.progress, xp.total), (0, 0.0, 0)); + xp.give(7); + assert_eq!((xp.level, xp.progress, xp.total), (1, 0.0, 7)); + } +} + #[cfg(test)] mod fire_environment_tests { use super::*; diff --git a/crates/horizon-client/src/front.rs b/crates/horizon-client/src/front.rs index 5b0a2c5ab..0b4eebd62 100644 --- a/crates/horizon-client/src/front.rs +++ b/crates/horizon-client/src/front.rs @@ -1173,6 +1173,7 @@ pub mod pause { quit_label: &str, opened: Instant, friends: &FriendsView, + remote: bool, ) { let (w, h) = (ui.w, ui.h); let p = t::ease_out_quint(opened.elapsed().as_secs_f32() / t::move_()); @@ -1207,11 +1208,11 @@ pub mod pause { Kind::Primary, true, ); - let lw = ui.button_width("Open to LAN", true); + let lw = ui.button_width("World Options", true); ui.button( act(9), [x + bw + 8.0, y, lw, CONTROL_LARGE], - "Open to LAN", + "World Options", Kind::Secondary, true, ); @@ -1235,7 +1236,11 @@ pub mod pause { x, y, "Leave", - "Saves the world, then returns to the title.", + if remote { + "Disconnects from the server, then returns to the title." + } else { + "Saves the world, then returns to the title." + }, cw - t::ROW_LABEL - 220.0, ); let qw = ui.button_width(quit_label, false); @@ -1363,6 +1368,7 @@ pub mod pause { world: &str, quit_label: &str, friends: &FriendsView, + remote: bool, ) -> Option { let mut ui = Ui::dry(atlas, batch, (x, y)); draw( @@ -1371,6 +1377,7 @@ pub mod pause { quit_label, Instant::now() - std::time::Duration::from_secs(5), friends, + remote, ); let hit = ui.hit((x, y))?; let nav = id("pause.nav", 0); @@ -1391,6 +1398,47 @@ mod tests { use super::*; use horizon_world::nbt::Tag; + #[test] + fn pause_world_options_and_disconnect_are_clickable_on_servers() { + let atlas = + HudAtlas::build(std::path::Path::new("/nonexistent/horizon-test-assets")).unwrap(); + let friends = FriendsView::default(); + for remote in [false, true] { + let quit = if remote { + "Disconnect" + } else { + "Save and quit" + }; + for action in [9u8, 2] { + let mut batch = HudBatch::new([1280, 720]); + let (rect, density) = { + let mut ui = Ui::dry(&atlas, &mut batch, (0.0, 0.0)); + pause::draw( + &mut ui, + "World", + quit, + Instant::now() - std::time::Duration::from_secs(5), + &friends, + remote, + ); + let hit = ui + .hits + .iter() + .find(|h| h.id == id("pause", u64::from(action))) + .expect("pause action available"); + (hit.rect, ui.density) + }; + let k = density / batch.scale; + let x = (rect[0] + rect[2]) / 2.0 * k; + let y = (rect[1] + rect[3]) / 2.0 * k; + assert_eq!( + pause::click(&atlas, &mut batch, x, y, "World", quit, &friends, remote), + Some(action) + ); + } + } + } + fn world(saves: &std::path::Path, folder: &str, last_played: i64) { crate::save::write_dat( &saves.join(folder).join("level.dat"), diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 73fcbbf52..117b83bc5 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -3104,6 +3104,7 @@ impl Game<'_> { self.eye = 1.62; self.previous_eye = 1.62; self.clock.reset(); + self.capture_loaded_world(); Ok(()) } fn tick(&mut self) -> Result<()> { @@ -3419,11 +3420,8 @@ impl Game<'_> { } if player.health.dead_or_dying() && self.screen != Screen::Dead { // Inventory.dropAll: every stack thrown in a random direction. - let at = [ - player.position.x, - player.position.y + 1.32, - player.position.z, - ]; + let feet = [player.position.x, player.position.y, player.position.z]; + let at = [feet[0], feet[1] + 1.32, feet[2]]; let killer = self.combat_killer_kind(); self.death_message(); // ServerPlayer.die: deaths, and the time-since counters restart. @@ -3439,6 +3437,10 @@ impl Game<'_> { } self.stats.reset("custom", "minecraft:time_since_death"); self.stats.reset("custom", "minecraft:time_since_rest"); + let reward = self + .experience + .death_reward(self.ui.rules.bool("keep_inventory") || self.spectator()); + self.spawn_orbs(feet, reward); if !self.creative && !self.ui.rules.bool("keep_inventory") { // Inventory.dropAll: slots 0..36, armor feet to head (36..39), off hand (40). let mut stacks: Vec = @@ -3661,6 +3663,10 @@ impl Game<'_> { ) || self.book.is_some()) } fn capture(&mut self, capture: bool) { + // MouseHandler.grabMouse never captures an inactive window. + if capture && !self.focused { + return; + } if !capture { self.stop_mining(); } @@ -3679,6 +3685,16 @@ impl Game<'_> { } window.set_cursor_visible(!self.captured); } + /// LevelLoadingScreen.onClose -> Gui.setScreen(null) -> grabMouse. + fn capture_loaded_world(&mut self) { + // Loading may finish after focus was lost or another screen opened. + if self.title.is_none() + && self.screen == Screen::Playing + && !self.remote.as_ref().is_some_and(|r| r.chat_input.is_some()) + { + self.capture(true); + } + } fn draw_item(&mut self, batch: &mut HudBatch, stack: &ItemStack, x: f32, y: f32) { // `GuiGraphics.renderItem`: the resolved item model (tints, foil and // special renderers included), then the decorations. @@ -5601,7 +5617,7 @@ impl Game<'_> { .block(mining.pos[0], mining.pos[1], mining.pos[2]); self.res .block_entity_render - .render_banner_breaking(&scene, mining.pos, state.0, &mut out); + .render_breaking(&scene, mining.pos, state.0, &mut out); } } // Experience orbs (ExperienceOrbRenderer): pulsing billboards from a 4x4 icon sheet. @@ -8460,12 +8476,23 @@ impl Game<'_> { let debug_lines = horizon_client::gizmos::camera_relative(&lines, at, view); let debug_lines_on_top = horizon_client::gizmos::camera_relative(&on_top, at, view); let debug_crosshair = horizon_client::gizmos::camera_relative(&crosshair.on_top, at, view); - // LevelRenderer.renderHitOutline: the outline shape's edges. + // LevelExtractor.extractBlockOutline: model translucency controls draw order. + let mut outline_after_terrain = false; let outline = if self.screen == Screen::Playing && !self.spectator() { self.pick() .map(|h| { let state = self.world.block(h.pos[0], h.pos[1], h.pos[2]); let f = self.res.facts.get(state); + outline_after_terrain = self + .pack + .assets + .model_catalog + .collect(state, BlockPos::new(h.pos[0], h.pos[1], h.pos[2])) + .is_ok_and(|models| { + models + .iter() + .any(|(_, model)| model.faces.iter().any(|f| f.translucent)) + }); let o = if f.outline_offset { self.pack .context @@ -8615,6 +8642,7 @@ impl Game<'_> { }), dark_disc: self.dark_disc(camera), outline, + outline_after_terrain, debug_lines: &debug_lines, debug_lines_on_top: &debug_lines_on_top, debug_crosshair: &debug_crosshair, @@ -10219,7 +10247,11 @@ pub fn run() -> Result<()> { let root = options.resources.clone(); let assets = Arc::new(assets); log::info!("load assets: {:.2}s", started.elapsed().as_secs_f32()); - let facts = BlockFacts::load(&root, assets.registry)?; + let behaviour_json: serde_json::Value = serde_json::from_reader(std::io::BufReader::new( + std::fs::File::open(root.join("block-behaviours.json"))?, + ))?; + let (facts, gameplay_projection) = + BlockFacts::load_with_projection(&root, assets.registry, &behaviour_json)?; let mob_data = horizon_client::mobs::MobData::load(&root, &facts); horizon_client::mobs::trial_spawner::load_registry(&root); log::info!("load facts: {:.2}s", started.elapsed().as_secs_f32()); @@ -10286,7 +10318,12 @@ pub fn run() -> Result<()> { ambient: horizon_client::ambience::AmbientTables::load(&root), nether_environment: Environment::load_dimension(&root, "the_nether", false)?, end_environment: Environment::load_dimension(&root, "the_end", false)?, - behaviours: Behaviours::load(registry_owner.registry, &root)?, + behaviours: Behaviours::load_with_gameplay( + registry_owner.registry, + &root, + &behaviour_json, + &gameplay_projection, + )?, mob_types: MobTypes::load(&root)? .types .into_iter() @@ -10298,6 +10335,10 @@ pub fn run() -> Result<()> { player_arm: horizon_client::mobs::load_model(&root, "minecraft:player#main") .and_then(|m| m.children.into_iter().find(|c| c.name == "right_arm")), }); + // Both inputs are needed only while constructing the behaviour tables. + // Release their owned JSON/Arc buffers before entering the long-lived game loop. + drop(gameplay_projection); + drop(behaviour_json); let mut settings = Settings::load(&std::env::current_dir()?.join("options.txt")); horizon_client::ui_theme::load_preferences(&std::env::current_dir()?); // Scripted and frame-limited runs (the parity harnesses) see vanilla's diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs index 3fc959027..5e3c69a11 100644 --- a/crates/horizon-client/src/game/lan.rs +++ b/crates/horizon-client/src/game/lan.rs @@ -754,6 +754,8 @@ impl Game<'_> { let Some(mut host) = self.lan.take() else { return; }; + // What the tick sends a guest goes to its connection at the end. + let holding = lan::Holding::start(); let state = self.lan_host_state(&host); // A dedicated server runs the hub without a host player. if state.is_some() || host.hub.config.dedicated { @@ -854,6 +856,10 @@ impl Game<'_> { self.lan_swings(&mut host); self.lan_update_streaming(&host); self.lan_update_models(&mut host); + drop(holding); + for g in &host.hub.guests { + g.sender.flush(); + } self.lan = Some(host); } diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 716bd6ae0..34c766dbb 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -562,6 +562,70 @@ impl Game<'_> { } } S::ChatCommand(c) => self.guest_command(host, conn, &c.command), + S::ChangeDifficulty(p) if host.hub.guests[gi].permission >= 2 => { + if !self.level.difficulty_locked && (0..=3).contains(&p.difficulty) { + self.ui.difficulty = if self.level.hardcore { + 3 + } else { + p.difficulty as u8 + }; + self.sync_rules(); + if self.ui.difficulty == 0 { + self.mobs.retain(|m| !m.hostile()); + } + host.hub + .broadcast(&C::ChangeDifficulty(play::ChangeDifficulty { + difficulty: i32::from(self.ui.difficulty), + locked: self.level.difficulty_locked, + })); + } + } + S::LockDifficulty(p) if host.hub.guests[gi].permission >= 2 => { + self.level.difficulty_locked = p.locked; + host.hub + .broadcast(&C::ChangeDifficulty(play::ChangeDifficulty { + difficulty: i32::from(self.ui.difficulty), + locked: self.level.difficulty_locked, + })); + } + S::ClientCommand(p) if p.action == 2 && host.hub.guests[gi].permission >= 2 => { + host.hub.send_to( + conn, + &C::GameRuleValues(play::GameRuleValues { + entries: horizon_client::gamerules::RULES + .iter() + .map(|r| play::GameRuleEntry { + name: format!("minecraft:{}", r.name), + value: self.ui.rules.get(r.name).unwrap_or(r.default).to_string(), + }) + .collect(), + }), + ); + } + S::SetGameRule(p) if host.hub.guests[gi].permission >= 2 => { + for entry in p.entries { + if self.ui.rules.set_string(&entry.name, &entry.value) { + let message = horizon_client::text::Text::tr( + "commands.gamerule.set", + &[&entry.name, &entry.value], + ); + let content = + horizon_client::lan::data::component_nbt(&message.component()); + for g in &host.hub.guests { + if g.permission >= 2 { + g.send(&C::SystemChat(play::SystemChat { + content: content.clone(), + overlay: false, + })); + } + } + if self.options.dedicated.is_none() && self.allow_commands() { + self.system_message(message); + } + } + } + self.sync_rules(); + } S::ChangeGameMode(p) if host.hub.guests[gi].permission >= 2 => { if let Some(mode) = usize::try_from(p.mode) .ok() @@ -853,6 +917,13 @@ impl Game<'_> { g.saturation = 5.0; g.sent_health = None; g.motion = None; + let mut xp = Experience { + level: g.xp_level, + progress: g.xp_progress, + total: g.xp_total, + }; + xp.respawn(self.ui.rules.bool("keep_inventory") || g.game_mode == SPECTATOR); + (g.xp_level, g.xp_progress, g.xp_total) = (xp.level, xp.progress, xp.total); // A new body: nothing given to the old one carries over. if let Some(play) = host.play.get_mut(&conn) { play.potions = Default::default(); @@ -938,6 +1009,12 @@ impl Game<'_> { g.dead = true; g.last_death = Some(g.position.map(|v| v.floor() as i32)); let (id, at) = (g.entity_id, g.position); + let reward = Experience { + level: g.xp_level, + progress: g.xp_progress, + total: g.xp_total, + } + .death_reward(self.ui.rules.bool("keep_inventory") || g.game_mode == SPECTATOR); let message = literal(&format!("{} died", g.name)); host.hub.send_to( conn, @@ -945,6 +1022,7 @@ impl Game<'_> { ); // LivingEntity.die: the death animation, the dying player included. host.hub.entity_event(id, 3, at); + self.spawn_orbs(at, reward); } } } diff --git a/crates/horizon-client/src/game/lan_screen.rs b/crates/horizon-client/src/game/lan_screen.rs index 7c4533a16..6be6fc7fa 100644 --- a/crates/horizon-client/src/game/lan_screen.rs +++ b/crates/horizon-client/src/game/lan_screen.rs @@ -4,6 +4,7 @@ //! difficulty, LAN on/off with its port, command access for guests and //! forcing the game mode. Its difficulty lock asks first (PopupScreen), and //! Restrictions opens RestrictionsScreen. +//! Parity reference: https://mcsrc.dev/2/26.3/net/minecraft/client/gui/screens/WorldOptionsScreen use super::{ Game, Screen, game_rules_screen::{Exit, RulesScreen}, @@ -16,9 +17,12 @@ use horizon_client::{ text::{Text, named_color}, ui::{self, EditBox}, }; +use horizon_protocol::packets::play::{self, Serverbound as S}; use winit::{event::KeyEvent, keyboard::PhysicalKey}; pub(super) struct WorldOptions { + remote: bool, + gamemaster: bool, default_mode: i32, personal_mode: i32, cheats: bool, @@ -109,6 +113,36 @@ fn labelled(key: &str, value: Text) -> Text { } impl WorldOptions { + /// Vanilla 26.3 WorldOptionsScreen.generalOptions: guests see difficulty, + /// game rules and restrictions; game modes, commands and LAN are host-only. + fn visible_buttons(&self, w: f32) -> Vec<(Button, f32, f32, f32)> { + if !self.remote { + return Self::buttons(w, self.top()); + } + let x = Self::left(w); + let top = self.top(); + vec![ + (Button::Difficulty, x, top + 29.0, 130.0), + (Button::Lock, x + 130.0, top + 29.0, 20.0), + (Button::GameRules, x + 158.0, top + 29.0, 150.0), + (Button::Restrictions, x, top + 53.0, 150.0), + ] + } + fn content_height(&self) -> f32 { + if self.remote { 81.0 } else { CONTENT } + } + fn scroll_limit(&self, h: f32) -> f32 { + (self.content_height() - (h - HEADER - FOOTER)).max(0.0) + } + fn server_difficulty(&mut self, difficulty: u8, locked: bool) { + // A server update is the new baseline, not a local edit. In particular, + // the reply to Apply may arrive after the screen has already reopened. + self.difficulty = difficulty; + self.difficulty_locked = locked; + self.locked = locked || self.hardcore; + self.initial.difficulty = self.difficulty; + self.initial.locked = self.locked; + } fn parsed_port(&self) -> Option { if self.port.value.is_empty() { return Some(self.hint); @@ -176,16 +210,13 @@ impl WorldOptions { /// scroll area. fn hit(&self, (x, y): (f32, f32), (w, h): (f32, f32)) -> Option