ATProto Browser

ATProto Browser

Experimental browser for the Atmosphere

Post

In the next version of Bun & Safari Polymorphic array access gets up to 8x faster, thanks to @yusukesuzuki.bsky.social

Apr 5, 2025, 12:02 AM

Record data

{
  "uri": "at://did:plc:76vf7xzncfaxw3m6qemqpmj4/app.bsky.feed.post/3llzmwuoly227",
  "cid": "bafyreifkovs6jmj4qvbgdxf4zhrqfjubseojexvxwclzqigi5xwlmwbhn4",
  "value": {
    "text": "In the next version of Bun & Safari\n\nPolymorphic array access gets up to 8x faster, thanks to \n@yusukesuzuki.bsky.social",
    "$type": "app.bsky.feed.post",
    "embed": {
      "$type": "app.bsky.embed.images",
      "images": [
        {
          "alt": "mport { run, bench } from \"mitata\";\n\n// Assuming the vectors are of the same length\nfunction cosineDistance(a, b) {\n  let dotProduct = 0;\n  let magA = 0;\n  let magB = 0;\n  for (let i = 0; i < a.length; i++) {\n    dotProduct += a[i] * b[i];\n    magA += a[i] * a[i];\n    magB += b[i] * b[i];\n  }\n  return 1 - dotProduct / (Math.sqrt(magA) * Math.sqrt(magB));\n}\n\n// Generate random data for testing\nconst dimensions = 1536; // Adjust dimensions as needed\nconst array1 = Array.from({ length: dimensions }, () => Math.random() * 100);\nconst array2 = Array.from({ length: dimensions }, () => Math.random() * 100);\nconst floatArray1 = new Float32Array(array1);\nconst floatArray2 = new Float32Array(array2);\n\nbench(\"Array\", () => {\n  cosineDistance(array1, array2);\n});\n\nbench(\"Float32Array\", () => {\n  cosineDistance(floatArray1, floatArray2);\n});\n\nawait run();\nbun-latest array.mjs # New\nclk: ~3.94 GHz\ncpu: Apple M3 Max\nruntime: bun 1.2.9 (arm64-darwin)\n\nbenchmark                   avg (min … max)\n-------------------------------------------\nArray                          1.07 µs/iter   1.07 µs  ▇▃ ▄█▂\n                        (1.06 µs … 1.13 µs)   1.09 µs ▄██▆███▇▅▄▄▄▂▂▂▁▁▁▁▂▂\nFloat32Array                   1.64 µs/iter   1.64 µs                   █\n                        (1.46 µs … 1.68 µs)   1.67 µs ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██▃▁\nbun-1.2.8 array.mjs # Prev\nclk: ~3.87 GHz\ncpu: Apple M3 Max\nruntime: bun 1.2.8 (arm64-darwin)\n\nbenchmark                   avg (min … max)\n-------------------------------------------\nArray                          1.07 µs/iter   1.07 µs  ▄  █▂\n                        (1.06 µs … 1.11 µs)   1.10 µs ▅█▆▆██▄▄▅▂▁▁▁▂▂▁▁▁▁▁▁\nFloat32Array                  13.52 µs/iter  13.50 µs  █   █\n                      (13.41 µs … 14.02 µs)  13.59 µs ██▁▁▁███▁██▁▁▁▁▁▁▁▁██\nnode array.mjs # Node, for comparison\nclk: ~3.94 GHz\ncpu: Apple M3 Max\nruntime: node 23.10.0 (arm64-darwin)\n\nbenchmark                   avg (min … max)\n-------------------------------------------\nArray        ",
          "image": {
            "$type": "blob",
            "ref": {
              "$link": "bafkreia3vkwzkaofkvwt5tzghe3yqysdgn4dml276nfnn27i7f3rkad4wy"
            },
            "mimeType": "image/jpeg",
            "size": 211302
          },
          "aspectRatio": {
            "width": 690,
            "height": 1024
          }
        }
      ]
    },
    "langs": [
      "en"
    ],
    "facets": [
      {
        "$type": "app.bsky.richtext.facet",
        "index": {
          "byteEnd": 120,
          "byteStart": 95
        },
        "features": [
          {
            "did": "did:plc:woplk5aamxiblg6wxueteg5h",
            "$type": "app.bsky.richtext.facet#mention"
          }
        ]
      }
    ],
    "createdAt": "2025-04-05T00:02:56.726Z"
  }
}