Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Encode methods accept []byte #36

Draft
wants to merge 50 commits into
base: main
Choose a base branch
from

Conversation

noisersup
Copy link
Member

@noisersup noisersup commented Sep 4, 2024

Closes #21.

Encoding benchmarks sped up by around 85-90%. The geomean is affected by much smaller improvements in logging benchmarks.

goos: linux
goarch: amd64
pkg: github.com/FerretDB/wire/wirebson
cpu: 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
                                        │    old.txt    │               new.txt                │
                                        │    sec/op     │    sec/op     vs base                │
Document/handshake1/Decode-8               419.8n ± 10%   387.9n ±  5%        ~ (p=0.063 n=10)
Document/handshake1/Encode-8              411.80n ±  4%   53.09n ±  2%  -87.11% (p=0.000 n=10)
Document/handshake1/LogValue-8             1.710µ ±  6%   1.633µ ±  8%        ~ (p=0.165 n=10)
Document/handshake1/LogMessage-8           2.034µ ±  8%   2.002µ ±  9%        ~ (p=0.218 n=10)
Document/handshake1/DecodeDeep-8           2.103µ ±  8%   1.822µ ±  8%  -13.34% (p=0.000 n=10)
Document/handshake1/EncodeDeep-8          1887.0n ±  8%   369.1n ±  3%  -80.44% (p=0.000 n=10)
Document/handshake1/LogValueDeep-8         7.727µ ±  5%   7.595µ ±  7%        ~ (p=0.165 n=10)
Document/handshake1/LogMessageDeep-8       21.66µ ± 11%   21.12µ ±  7%        ~ (p=0.393 n=10)
Document/handshake2/Decode-8               449.4n ±  6%   406.1n ± 14%   -9.65% (p=0.002 n=10)
Document/handshake2/Encode-8              402.85n ±  8%   54.89n ±  4%  -86.37% (p=0.000 n=10)
Document/handshake2/LogValue-8             1.791µ ±  4%   1.751µ ±  9%        ~ (p=0.393 n=10)
Document/handshake2/LogMessage-8           2.092µ ±  7%   1.931µ ±  6%   -7.74% (p=0.004 n=10)
Document/handshake2/DecodeDeep-8           2.162µ ± 13%   1.772µ ±  6%  -18.06% (p=0.000 n=10)
Document/handshake2/EncodeDeep-8          1952.5n ±  4%   355.3n ±  1%  -81.80% (p=0.000 n=10)
Document/handshake2/LogValueDeep-8         7.798µ ±  7%   7.581µ ±  5%        ~ (p=0.315 n=10)
Document/handshake2/LogMessageDeep-8       22.14µ ±  9%   20.09µ ±  9%   -9.24% (p=0.023 n=10)
Document/handshake3/Decode-8               394.6n ±  8%   368.6n ±  6%   -6.60% (p=0.001 n=10)
Document/handshake3/Encode-8              271.70n ±  9%   42.67n ±  5%  -84.29% (p=0.000 n=10)
Document/handshake3/LogValue-8             1.308µ ±  6%   1.225µ ±  5%   -6.38% (p=0.004 n=10)
Document/handshake3/LogMessage-8           651.8n ±  4%   600.8n ±  8%   -7.83% (p=0.011 n=10)
Document/handshake3/DecodeDeep-8           579.4n ±  9%   495.1n ±  5%  -14.55% (p=0.000 n=10)
Document/handshake3/EncodeDeep-8          465.85n ±  8%   65.48n ±  6%  -85.94% (p=0.000 n=10)
Document/handshake3/LogValueDeep-8         3.517µ ±  5%   3.423µ ±  7%        ~ (p=0.123 n=10)
Document/handshake3/LogMessageDeep-8       2.004µ ±  5%   1.877µ ±  6%   -6.31% (p=0.022 n=10)
Document/handshake4/Decode-8               1.726µ ± 11%   1.458µ ± 12%  -15.50% (p=0.003 n=10)
Document/handshake4/Encode-8              1031.0n ± 10%   191.6n ±  7%  -81.41% (p=0.000 n=10)
Document/handshake4/LogValue-8             5.708µ ± 12%   5.343µ ±  6%   -6.39% (p=0.029 n=10)
Document/handshake4/LogMessage-8           6.679µ ± 13%   5.620µ ±  4%  -15.86% (p=0.001 n=10)
Document/handshake4/DecodeDeep-8           5.298µ ±  4%   4.591µ ± 14%  -13.35% (p=0.004 n=10)
Document/handshake4/EncodeDeep-8          3999.5n ± 10%   693.6n ±  5%  -82.66% (p=0.000 n=10)
Document/handshake4/LogValueDeep-8         18.11µ ±  6%   18.58µ ± 10%        ~ (p=0.579 n=10)
Document/handshake4/LogMessageDeep-8       24.56µ ±  0%   23.59µ ±  0%   -3.97% (p=0.000 n=10)
Document/all/Decode-8                      1.394µ ± 14%   1.261µ ± 10%   -9.51% (p=0.015 n=10)
Document/all/Encode-8                      591.4n ±  7%   131.0n ±  3%  -77.84% (p=0.000 n=10)
Document/all/LogValue-8                    4.620µ ±  7%   4.630µ ±  6%        ~ (p=0.796 n=10)
Document/all/LogMessage-8                  3.935µ ± 15%   4.271µ ± 11%        ~ (p=0.481 n=10)
Document/all/DecodeDeep-8                  5.097µ ± 12%   4.951µ ± 10%        ~ (p=0.616 n=10)
Document/all/EncodeDeep-8                 4041.0n ±  2%   882.8n ±  3%  -78.15% (p=0.000 n=10)
Document/all/LogValueDeep-8                20.38µ ±  8%   20.53µ ±  4%        ~ (p=0.912 n=10)
Document/all/LogMessageDeep-8              9.905µ ± 11%   9.903µ ±  7%        ~ (p=0.853 n=10)
Document/nested/Decode-8                   125.5n ±  7%   113.7n ±  7%   -9.44% (p=0.001 n=10)
Document/nested/Encode-8                  272.30n ±  0%   21.20n ±  6%  -92.21% (p=0.000 n=10)
Document/nested/LogValue-8                 596.6n ±  6%   570.4n ±  4%   -4.38% (p=0.023 n=10)
Document/nested/LogMessage-8               192.0n ±  4%   183.9n ±  4%   -4.19% (p=0.001 n=10)
Document/nested/DecodeDeep-8               19.87µ ±  6%   19.95µ ±  5%        ~ (p=0.631 n=10)
Document/nested/EncodeDeep-8               227.4µ ±  5%   293.0µ ±  0%  +28.87% (p=0.000 n=10)
Document/nested/LogValueDeep-8             13.06µ ±  5%   13.18µ ± 10%        ~ (p=0.579 n=10)
Document/nested/LogMessageDeep-8           19.96µ ± 10%   19.00µ ± 10%   -4.81% (p=0.035 n=10)
Document/float64Doc/Decode-8               105.6n ±  4%   100.3n ± 10%        ~ (p=0.239 n=10)
Document/float64Doc/Encode-8              146.30n ±  6%   16.26n ±  3%  -88.89% (p=0.000 n=10)
Document/float64Doc/LogValue-8             768.4n ±  9%   767.7n ±  6%        ~ (p=0.529 n=10)
Document/float64Doc/LogMessage-8           275.1n ±  5%   264.7n ±  4%        ~ (p=0.089 n=10)
Document/float64Doc/DecodeDeep-8          108.20n ±  7%   98.19n ±  7%   -9.25% (p=0.000 n=10)
Document/float64Doc/EncodeDeep-8          146.95n ±  9%   15.84n ±  6%  -89.22% (p=0.000 n=10)
Document/float64Doc/LogValueDeep-8         767.5n ±  6%   764.4n ±  6%        ~ (p=0.436 n=10)
Document/float64Doc/LogMessageDeep-8       280.1n ±  4%   268.5n ±  5%        ~ (p=0.063 n=10)
Document/stringDoc/Decode-8                124.5n ±  9%   118.8n ±  5%   -4.62% (p=0.037 n=10)
Document/stringDoc/Encode-8               140.50n ±  4%   17.62n ±  3%  -87.46% (p=0.000 n=10)
Document/stringDoc/LogValue-8              467.8n ±  7%   457.8n ±  4%        ~ (p=0.280 n=10)
Document/stringDoc/LogMessage-8            168.8n ±  4%   164.6n ±  5%   -2.52% (p=0.019 n=10)
Document/stringDoc/DecodeDeep-8            121.3n ±  9%   114.7n ±  9%        ~ (p=0.118 n=10)
Document/stringDoc/EncodeDeep-8           141.70n ±  8%   17.99n ±  5%  -87.30% (p=0.000 n=10)
Document/stringDoc/LogValueDeep-8          453.6n ±  6%   457.5n ±  6%        ~ (p=0.796 n=10)
Document/stringDoc/LogMessageDeep-8        172.8n ±  4%   165.8n ±  4%   -4.08% (p=0.023 n=10)
Document/binaryDoc/Decode-8                144.3n ±  6%   137.9n ± 10%   -4.44% (p=0.035 n=10)
Document/binaryDoc/Encode-8               145.45n ±  9%   17.80n ±  4%  -87.76% (p=0.000 n=10)
Document/binaryDoc/LogValue-8              995.8n ±  6%   964.5n ±  8%        ~ (p=0.105 n=10)
Document/binaryDoc/LogMessage-8            214.7n ±  4%   202.5n ±  4%   -5.71% (p=0.005 n=10)
Document/binaryDoc/DecodeDeep-8            143.8n ±  7%   131.7n ±  6%   -8.45% (p=0.019 n=10)
Document/binaryDoc/EncodeDeep-8           141.80n ±  7%   17.31n ±  6%  -87.79% (p=0.000 n=10)
Document/binaryDoc/LogValueDeep-8          963.2n ±  5%   949.6n ±  7%        ~ (p=0.616 n=10)
Document/binaryDoc/LogMessageDeep-8        215.8n ±  7%   198.7n ±  4%   -7.90% (p=0.003 n=10)
Document/objectIDDoc/Decode-8              124.6n ± 12%   108.2n ±  8%  -13.20% (p=0.007 n=10)
Document/objectIDDoc/Encode-8             159.35n ±  5%   18.43n ±  5%  -88.43% (p=0.000 n=10)
Document/objectIDDoc/LogValue-8            668.7n ±  8%   631.4n ±  6%   -5.58% (p=0.043 n=10)
Document/objectIDDoc/LogMessage-8          235.0n ±  6%   220.3n ±  5%   -6.26% (p=0.041 n=10)
Document/objectIDDoc/DecodeDeep-8          120.1n ± 13%   106.8n ±  6%  -11.12% (p=0.000 n=10)
Document/objectIDDoc/EncodeDeep-8         155.80n ±  5%   17.95n ±  5%  -88.48% (p=0.000 n=10)
Document/objectIDDoc/LogValueDeep-8        645.4n ±  6%   619.9n ±  5%   -3.96% (p=0.035 n=10)
Document/objectIDDoc/LogMessageDeep-8      238.7n ±  5%   218.9n ±  8%   -8.25% (p=0.002 n=10)
Document/boolDoc/Decode-8                  98.36n ± 11%   86.16n ±  5%  -12.39% (p=0.002 n=10)
Document/boolDoc/Encode-8                 131.40n ±  6%   16.55n ±  4%  -87.40% (p=0.000 n=10)
Document/boolDoc/LogValue-8                511.8n ±  6%   519.8n ±  4%        ~ (p=0.579 n=10)
Document/boolDoc/LogMessage-8              123.9n ±  5%   119.7n ±  2%   -3.39% (p=0.009 n=10)
Document/boolDoc/DecodeDeep-8              95.14n ±  3%   86.37n ± 11%   -9.22% (p=0.011 n=10)
Document/boolDoc/EncodeDeep-8             128.15n ±  3%   17.07n ±  6%  -86.68% (p=0.000 n=10)
Document/boolDoc/LogValueDeep-8            513.0n ±  5%   519.6n ±  5%        ~ (p=0.579 n=10)
Document/boolDoc/LogMessageDeep-8          123.0n ±  4%   120.7n ±  3%        ~ (p=0.247 n=10)
Document/timeDoc/Decode-8                  131.3n ±  4%   124.6n ±  5%   -5.06% (p=0.019 n=10)
Document/timeDoc/Encode-8                 155.25n ± 12%   18.32n ±  9%  -88.20% (p=0.000 n=10)
Document/timeDoc/LogValue-8                963.9n ±  6%   913.8n ± 12%        ~ (p=0.143 n=10)
Document/timeDoc/LogMessage-8              248.1n ±  6%   224.4n ±  6%   -9.55% (p=0.000 n=10)
Document/timeDoc/DecodeDeep-8              134.9n ±  8%   121.9n ±  4%   -9.64% (p=0.001 n=10)
Document/timeDoc/EncodeDeep-8             149.65n ±  5%   18.50n ±  9%  -87.64% (p=0.000 n=10)
Document/timeDoc/LogValueDeep-8            971.8n ±  6%   913.3n ±  3%   -6.01% (p=0.002 n=10)
Document/timeDoc/LogMessageDeep-8          240.5n ±  4%   235.3n ±  4%        ~ (p=0.118 n=10)
Document/nullDoc/Decode-8                  97.55n ±  4%   86.48n ±  9%  -11.36% (p=0.001 n=10)
Document/nullDoc/Encode-8                 127.10n ±  5%   16.93n ±  7%  -86.68% (p=0.000 n=10)
Document/nullDoc/LogValue-8                596.8n ±  5%   589.8n ±  4%        ~ (p=0.210 n=10)
Document/nullDoc/LogMessage-8              126.5n ±  6%   118.7n ±  3%   -6.13% (p=0.006 n=10)
Document/nullDoc/DecodeDeep-8              96.54n ±  6%   83.70n ± 13%  -13.31% (p=0.001 n=10)
Document/nullDoc/EncodeDeep-8             128.45n ±  5%   16.18n ±  6%  -87.40% (p=0.000 n=10)
Document/nullDoc/LogValueDeep-8            595.9n ±  8%   577.9n ±  4%        ~ (p=0.105 n=10)
Document/nullDoc/LogMessageDeep-8          124.9n ±  5%   118.7n ±  4%   -4.93% (p=0.019 n=10)
Document/regexDoc/Decode-8                 143.7n ±  3%   132.3n ±  9%   -7.90% (p=0.005 n=10)
Document/regexDoc/Encode-8                148.10n ±  7%   20.71n ±  4%  -86.02% (p=0.000 n=10)
Document/regexDoc/LogValue-8               916.6n ±  6%   911.7n ±  7%        ~ (p=1.000 n=10)
Document/regexDoc/LogMessage-8             142.9n ±  3%   139.8n ±  2%   -2.17% (p=0.015 n=10)
Document/regexDoc/DecodeDeep-8             137.8n ±  7%   135.5n ±  7%        ~ (p=0.247 n=10)
Document/regexDoc/EncodeDeep-8            146.90n ±  4%   20.58n ±  3%  -85.99% (p=0.000 n=10)
Document/regexDoc/LogValueDeep-8           904.4n ±  7%   900.5n ±  7%        ~ (p=0.631 n=10)
Document/regexDoc/LogMessageDeep-8         143.8n ±  3%   140.7n ±  3%   -2.16% (p=0.002 n=10)
Document/int32Doc/Decode-8                114.25n ± 11%   97.17n ±  4%  -14.95% (p=0.000 n=10)
Document/int32Doc/Encode-8                140.45n ±  6%   15.88n ±  5%  -88.69% (p=0.000 n=10)
Document/int32Doc/LogValue-8               617.2n ±  6%   598.5n ±  8%        ~ (p=0.247 n=10)
Document/int32Doc/LogMessage-8             159.9n ±  9%   152.8n ±  6%   -4.44% (p=0.025 n=10)
Document/int32Doc/DecodeDeep-8            104.95n ±  9%   96.83n ±  5%   -7.74% (p=0.015 n=10)
Document/int32Doc/EncodeDeep-8            138.70n ±  4%   16.40n ±  3%  -88.17% (p=0.000 n=10)
Document/int32Doc/LogValueDeep-8           621.1n ±  5%   582.7n ±  9%   -6.18% (p=0.035 n=10)
Document/int32Doc/LogMessageDeep-8         163.8n ±  5%   156.8n ±  3%   -4.27% (p=0.033 n=10)
Document/timestampDoc/Decode-8             96.56n ±  7%   91.81n ± 12%        ~ (p=0.089 n=10)
Document/timestampDoc/Encode-8            147.70n ±  4%   16.74n ±  6%  -88.67% (p=0.000 n=10)
Document/timestampDoc/LogValue-8           556.0n ±  6%   562.6n ±  5%        ~ (p=0.579 n=10)
Document/timestampDoc/LogMessage-8         159.6n ±  7%   156.7n ±  4%        ~ (p=0.190 n=10)
Document/timestampDoc/DecodeDeep-8         93.66n ±  9%   84.67n ±  9%   -9.60% (p=0.003 n=10)
Document/timestampDoc/EncodeDeep-8        150.15n ±  5%   16.74n ±  5%  -88.85% (p=0.000 n=10)
Document/timestampDoc/LogValueDeep-8       541.6n ±  4%   540.6n ±  3%        ~ (p=0.971 n=10)
Document/timestampDoc/LogMessageDeep-8     163.1n ±  6%   163.5n ±  4%        ~ (p=0.424 n=10)
Document/int64Doc/Decode-8                 111.7n ±  4%   100.1n ±  6%  -10.38% (p=0.000 n=10)
Document/int64Doc/Encode-8                148.75n ±  4%   15.86n ±  7%  -89.34% (p=0.000 n=10)
Document/int64Doc/LogValue-8               617.9n ±  6%   611.5n ±  7%        ~ (p=0.796 n=10)
Document/int64Doc/LogMessage-8             214.2n ±  8%   206.1n ±  5%        ~ (p=0.123 n=10)
Document/int64Doc/DecodeDeep-8             107.8n ±  5%   104.0n ± 11%   -3.53% (p=0.023 n=10)
Document/int64Doc/EncodeDeep-8            147.90n ±  9%   16.79n ±  6%  -88.64% (p=0.000 n=10)
Document/int64Doc/LogValueDeep-8           609.0n ±  4%   632.2n ± 11%        ~ (p=0.280 n=10)
Document/int64Doc/LogMessageDeep-8         220.2n ±  6%   205.0n ±  8%   -6.86% (p=0.023 n=10)
Document/decimal128Doc/Decode-8            118.6n ±  4%   106.6n ±  6%  -10.08% (p=0.000 n=10)
Document/decimal128Doc/Encode-8           160.95n ±  8%   16.30n ±  7%  -89.87% (p=0.000 n=10)
Document/decimal128Doc/LogValue-8          886.0n ±  7%   849.8n ±  6%        ~ (p=0.165 n=10)
Document/decimal128Doc/LogMessage-8        172.2n ±  6%   169.5n ±  4%        ~ (p=0.085 n=10)
Document/decimal128Doc/DecodeDeep-8        118.2n ±  9%   109.3n ±  5%   -7.53% (p=0.011 n=10)
Document/decimal128Doc/EncodeDeep-8       161.60n ±  3%   16.76n ±  4%  -89.63% (p=0.000 n=10)
Document/decimal128Doc/LogValueDeep-8      875.8n ±  6%   833.1n ±  8%        ~ (p=0.143 n=10)
Document/decimal128Doc/LogMessageDeep-8    172.3n ±  4%   170.1n ±  7%        ~ (p=0.631 n=10)
Document/smallDoc/Decode-8                 132.6n ±  4%   123.3n ±  4%   -6.98% (p=0.000 n=10)
Document/smallDoc/Encode-8                115.50n ±  8%   13.72n ±  6%  -88.12% (p=0.000 n=10)
Document/smallDoc/LogValue-8               556.5n ±  8%   560.3n ±  6%        ~ (p=1.000 n=10)
Document/smallDoc/LogMessage-8             178.1n ±  5%   170.2n ±  5%        ~ (p=0.123 n=10)
Document/smallDoc/DecodeDeep-8             144.6n ± 12%   134.3n ±  9%   -7.06% (p=0.019 n=10)
Document/smallDoc/EncodeDeep-8            207.05n ± 11%   15.23n ±  6%  -92.64% (p=0.000 n=10)
Document/smallDoc/LogValueDeep-8           190.4n ±  5%   181.2n ±  6%   -4.81% (p=0.023 n=10)
Document/smallDoc/LogMessageDeep-8         129.6n ±  5%   128.7n ±  3%        ~ (p=0.138 n=10)
Document/smallArray/Decode-8               138.0n ± 10%   124.3n ±  6%   -9.93% (p=0.000 n=10)
Document/smallArray/Encode-8              119.60n ±  4%   13.54n ±  6%  -88.68% (p=0.000 n=10)
Document/smallArray/LogValue-8             564.5n ±  9%   521.8n ±  6%        ~ (p=0.052 n=10)
Document/smallArray/LogMessage-8           172.4n ±  6%   174.2n ±  5%        ~ (p=0.698 n=10)
Document/smallArray/DecodeDeep-8           172.8n ±  4%   157.9n ±  3%   -8.60% (p=0.000 n=10)
Document/smallArray/EncodeDeep-8          212.90n ±  5%   15.32n ±  7%  -92.80% (p=0.000 n=10)
Document/smallArray/LogValueDeep-8         192.2n ±  5%   178.6n ±  2%   -7.13% (p=0.000 n=10)
Document/smallArray/LogMessageDeep-8       128.9n ±  4%   125.9n ±  6%        ~ (p=0.256 n=10)
Document/duplicateKeys/Decode-8            166.8n ±  4%   152.9n ±  9%   -8.36% (p=0.015 n=10)
Document/duplicateKeys/Encode-8           168.30n ±  4%   28.95n ±  4%  -82.80% (p=0.000 n=10)
Document/duplicateKeys/LogValue-8          817.2n ±  4%   832.8n ±  5%        ~ (p=0.481 n=10)
Document/duplicateKeys/LogMessage-8        231.2n ±  6%   220.8n ±  9%        ~ (p=0.143 n=10)
Document/duplicateKeys/DecodeDeep-8        171.0n ±  9%   154.3n ±  4%   -9.77% (p=0.001 n=10)
Document/duplicateKeys/EncodeDeep-8       167.25n ±  7%   28.23n ±  6%  -83.12% (p=0.000 n=10)
Document/duplicateKeys/LogValueDeep-8      835.3n ±  7%   809.1n ±  5%        ~ (p=0.436 n=10)
Document/duplicateKeys/LogMessageDeep-8    227.2n ±  5%   228.0n ±  4%        ~ (p=1.000 n=10)
geomean                                    428.4n         249.7n        -41.72%

@codecov-commenter
Copy link

codecov-commenter commented Sep 4, 2024

Codecov Report

Attention: Patch coverage is 78.43137% with 22 lines in your changes missing coverage. Please review.

Project coverage is 67.31%. Comparing base (21df9df) to head (e9b08a7).

Files with missing lines Patch % Lines
wirebson/encode.go 90.62% 4 Missing and 2 partials ⚠️
op_reply.go 0.00% 4 Missing ⚠️
wirebson/raw_array.go 0.00% 3 Missing ⚠️
wirebson/raw_document.go 0.00% 3 Missing ⚠️
op_query.go 0.00% 2 Missing ⚠️
wirebson/array.go 81.81% 1 Missing and 1 partial ⚠️
wirebson/document.go 80.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #36      +/-   ##
==========================================
+ Coverage   65.81%   67.31%   +1.49%     
==========================================
  Files          41       41              
  Lines        1805     1802       -3     
==========================================
+ Hits         1188     1213      +25     
+ Misses        447      435      -12     
+ Partials      170      154      -16     
Files with missing lines Coverage Δ
op_msg.go 73.51% <100.00%> (+0.14%) ⬆️
wirebson/bson.go 89.47% <ø> (ø)
wirebson/objectid.go 77.77% <ø> (ø)
wirebson/size.go 96.00% <100.00%> (ø)
op_query.go 47.25% <0.00%> (-0.53%) ⬇️
wirebson/array.go 70.42% <81.81%> (+5.63%) ⬆️
wirebson/document.go 51.92% <80.00%> (+3.84%) ⬆️
wirebson/raw_array.go 21.21% <0.00%> (-0.67%) ⬇️
wirebson/raw_document.go 84.00% <0.00%> (-1.14%) ⬇️
op_reply.go 44.87% <0.00%> (-1.19%) ⬇️
... and 1 more

... and 1 file with indirect coverage changes

Flag Coverage Δ
test 67.31% <78.43%> (+1.49%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@mergify mergify bot removed the conflict PRs that have merge conflicts label Sep 13, 2024
Copy link

mergify bot commented Sep 13, 2024

@noisersup this pull request has merge conflicts.

@mergify mergify bot added the conflict PRs that have merge conflicts label Sep 13, 2024
@mergify mergify bot removed the conflict PRs that have merge conflicts label Sep 16, 2024
@noisersup noisersup added the code/chore Code maintenance improvements label Sep 16, 2024
@noisersup noisersup marked this pull request as ready for review September 16, 2024 10:56
@noisersup noisersup requested review from a team, rumyantseva and chilagrow September 16, 2024 10:56
@noisersup noisersup enabled auto-merge (squash) September 16, 2024 10:56
@AlekSi AlekSi marked this pull request as draft September 19, 2024 15:54
auto-merge was automatically disabled September 19, 2024 15:54

Pull request was converted to draft

must.BeTrue(raw != nil)
return raw, nil
copy(out, raw) // FIXME
Copy link
Member

Choose a reason for hiding this comment

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

That part is very unfortunate. The whole idea was to avoid making extra copies – and here, we have to make an extra copy to satisfy the interface. Maybe we should drop AnyDocument/AnyArray altogether?..

On hold for now

Copy link
Member Author

@noisersup noisersup Sep 19, 2024

Choose a reason for hiding this comment

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

I also wasn't satisfied with this solution, but it seems to be the only solution with our current AnyDocument contract.

If we want to stay with Any(Document/Array) we might consider passing pointer to RawDocument as an argument instead.

On the other hand the improvements from Encode of non-raw objects affect benchmark results significantly, so we could merge this one and create another issue to improve raw objects. What do you think?

EDIT: If I think about it know I'm not sure if we even have (RawDocument).Encode() benchmarks

Copy link
Member

Choose a reason for hiding this comment

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

The benchmark results are a bit misleading: the speedup comes (as expected!) from the fact that we re-use the memory. But to benefit from it, we need to actually reuse the memory in FerretDB, and we haven't done that yet.

Let's release the first version of FerretDB v2 first, and then try again with this PR.

Copy link

mergify bot commented Sep 23, 2024

@noisersup this pull request has merge conflicts.

@mergify mergify bot added the conflict PRs that have merge conflicts label Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code/chore Code maintenance improvements conflict PRs that have merge conflicts
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

Encode methods should accept []byte
3 participants