Skip to content

Untrusted files, long sessions and speed

What the library promises when it is fed files it cannot trust, when it runs for hours while avatars come and go, and what it is held to for speed on each class of machine. Use this page when you take avatar files, manifests or custom items from players, run a server, or set a frame budget.

Untrusted input

Every decoder takes its bytes as untrusted. A file that is cut short, padded, or built to mislead gives an error code, not a crash, and a part that decodes keeps its promises: indices inside the vertices, finite positions and uvs.

sona_manifest m;
/* any 1,000 bytes from a player */
if (sona_manifest_parse(manifest, &m) != SONA_OK)
  puts("not an avatar");                            /* SONA_E_MANIFEST */
else
  /* its items load through your sources */
  sona_avatar_add(ctx, manifest, NULL, &avatar);
sona::Manifest m;
// any 1,000 bytes from a player
if (sona::Manifest::parse(manifest, m) != SONA_OK)
  std::puts("not an avatar");                        // SONA_E_MANIFEST
else
  // its items load through your sources
  avatar = ctx.add(manifest);
try
{
    // any 1,000 bytes from a player
    SonaManifests.Parse(manifest);
    // its items load through your sources
    avatar = ctx.Add(manifest);
}
// SONA_E_MANIFEST
catch (SonaException) { Console.WriteLine("not an avatar"); }
// any 1,000 bytes from a player
match Manifest::parse(&manifest) {
    // its items load through your sources
    Ok(_) => { ctx.add(&manifest, &AddOptions::default())?; }
    Err(_) => println!("not an avatar"),     // SONA_E_MANIFEST
}
try:
    sona.Manifest(manifest)                  # any 1,000 bytes from a player
    # its items load through your sources
    avatar = ctx.add(manifest)
except sona.SonaError:
    print("not an avatar")                   # SONA_E_MANIFEST
Input Read by What a bad one gives
A manifest, as bytes or base64 sona_manifest_parse, sona_avatar_add_base64 SONA_E_MANIFEST; one that parses writes back byte for byte
Item files from a source (models, textures, clips, shape overrides) The loader, inside sona_update The avatar is SONA_AVATAR_FAILED with its item named in SONA_EVENT_FAILED; other avatars are not touched
Console storage (STFS packages, FATX images, profile files) SONA_SOURCE_CONSOLE A read error for that file
A custom item (.sonaitem) sona_custom_item_check, sona_custom_item_add An error from the call; nothing is added
An imported animation (BVH, glTF, glb, FBX) sona_anim_file_open An error from the open; no clip is made
A prop's model and pictures (glTF, PNG, JPEG) sona_prop_mesh_load, sona_prop_mesh_open An error from the call; no mesh is made
A saved state sona_avatar_load_state SONA_E_CORRUPT for bytes that are not a state, SONA_E_UNSUPPORTED for a newer format
A network packet sona_net_read An error from the call; the receiver keeps its state

The decoders are fuzzed: containers, models, clips, textures, manifests and custom items each have a target that feeds them mutated files under the address and undefined-behaviour sanitisers.

Long sessions

Memory stays flat as avatars are added and removed. What grows are bounded caches, each inside its budget in sona_config.budget: the decoded items and clips that no avatar uses now, and the face sheets (every new mix of a face and an expression is a sheet). Removing an avatar frees what only it used; sona_stats reports the library's CPU and GPU memory at any time.

sona-bench, in your download's bench/ folder, has a soak scene that swaps a crowd's avatars for others for as long as you say and fails (exit 4) when memory, less what the caches hold, grows from one cycle of swaps to the next:

sona-bench --scene soak --backend vk --source dir:<folder of avatar files>
    --outfits random \
  --catalogue sona-catalogue.bin --counts 1000 --seconds 1800 --verbose

--budget-mb N sets every cache budget at once; --backend none soaks the core without drawing; --verbose prints each sample with the core's memory per tag. The soak reads its avatar files from a folder (dir:), so the network does not enter the numbers; the other scenes also take --source gate:<url>.

Speed targets

The library is held to these on each class of machine, with every avatar in its own random outfit and body:

Class Machine Targets (each a set limit)
Desktop A mid desktop GPU (RTX 4000 Ada, about an RTX 4060 Ti) 1,000 different avatars under 8 ms a frame, ready under 10 s, under 1.5 MB each; 10,000 in a stadium with LOD under 16 ms
Integrated GPU Core Ultra 9 185H with its Arc iGPU 1,000 different avatars under 16 ms; 10,000 with LOD under 16 ms and ready under 30 s; one more avatar ready and drawn from memory under 50 ms
Handheld Steam Deck 200 at 60 fps, 1,000 with LOD at 30 fps
Phone A low-end Android phone 20 at 60 fps on the low tier
Xbox 360 The console 10 at 30 fps

Performance has the measured figures for the first two and the command to measure your own machine.

What the renderer does to meet them:

  • Vertex cache order. Opaque meshes are uploaded in an order that runs the vertex shader about once per vertex; blended meshes keep their order.
  • Simplified meshes for small avatars. With sona_lod_set, an opaque mesh of an avatar under 120 pixels tall draws about half its triangles (edge collapses by quadric error; every vertex, seam and open border kept). The lists are made on the workers. Without sona_lod_set every avatar draws all its triangles (crowds).
  • Faces bake on the workers, in rows, to the same bytes as on one thread.
  • Vulkan without resizable BAR. Vertex and index data are uploaded through staging into memory the CPU does not map, so draws do not read them across the bus. SONA_VK_STAGE_GEOMETRY=0 or 1 in the environment overrides the choice.

An integrated GPU shares its power budget with the CPU: measure it with nothing else running.

This page as Markdown · All the docs as one file (llms-full.txt)