Skip to content

Virtual and reflective data structures for AssemblyScript

License

Notifications You must be signed in to change notification settings

JairusSW/as-virtual

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Virtual Type

The Virtual type is an efficient implementation for referencing segments of data without the need for constant memory allocations. This is particularly useful for tasks such as JSON parsing, where frequent slicing of strings can lead to high allocation rates. By using Virtual, you can reference memory segments directly, improving performance significantly. For example, this JSON implementation perviously parsed a Vec3 at 8,159,838m ops/s and with as-variant, it hit 39,260,740m ops/s.

Installation

npm install as-virtual

Usage

import { Virtual } from "as-virtual/assembly";

const virt = new Virtual<string>("foo bar", 3 << 1);
// Equiv. to "foo bar".slice(3)
// Note that we are referencing the memory directly and are using UTF-16

virt.equals("foo"); // true
virt.equals("baz"); // false

const virt2 = new Virtual<string>(" baz");
// Reinstantiate Virtual with new data
virt.reinst("bar", 6 << 1);

// Concat "bar" and " baz"
virt.merge(virt2);

console.log(virt.copyOut());

About

Virtual and reflective data structures for AssemblyScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published