Skip to content

Commit

Permalink
Improve array access performance (#1625)
Browse files Browse the repository at this point in the history
* always have JsValue in array and use sparse as helper to remove type checks
* faster paths for HasProperty against arrays
* remove JsArray constructor taking PropertyDescriptor[]
  • Loading branch information
lahma authored Aug 29, 2023
1 parent 7fd4893 commit 553fdb8
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 357 deletions.
28 changes: 0 additions & 28 deletions Jint.Tests.PublicInterface/RavenApiUsageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Jint.Native;
using Jint.Native.Function;
using Jint.Runtime;
using Jint.Runtime.Descriptors;
using Jint.Runtime.Interop;

namespace Jint.Tests.PublicInterface;
Expand Down Expand Up @@ -57,20 +56,6 @@ public void CanChangeMaxStatementValue()
Assert.Equal(321, constraint.MaxStatements);
}

[Fact]
public void CanConstructArrayInstanceFromDescriptorArray()
{
var descriptors = new[]
{
new PropertyDescriptor(42, writable: false, enumerable: false, configurable: false),
};

var engine = new Engine();
var array = new JsArray(engine, descriptors);
Assert.Equal(1L, array.Length);
Assert.Equal(42, array[0]);
}

[Fact]
public void CanGetPropertyDescriptor()
{
Expand All @@ -97,15 +82,6 @@ public void CanInjectConstructedObjects()

TestArrayAccess(engine, array1, "array1");

var array3 = new JsArray(engine, new[]
{
new PropertyDescriptor(JsNumber.Create(1), true, true, true),
new PropertyDescriptor(JsNumber.Create(2), true, true, true),
new PropertyDescriptor(JsNumber.Create(3), true, true, true),
});
engine.SetValue("array3", array3);
TestArrayAccess(engine, array3, "array3");

engine.SetValue("obj", obj);
Assert.Equal("test", engine.Evaluate("obj.name"));

Expand All @@ -117,10 +93,6 @@ public void CanInjectConstructedObjects()
Assert.Equal(0, engine.Evaluate("emptyArray.length"));
Assert.Equal(1, engine.Evaluate("emptyArray.push(1); return emptyArray.length"));

engine.SetValue("emptyArray", new JsArray(engine, Array.Empty<PropertyDescriptor>()));
Assert.Equal(0, engine.Evaluate("emptyArray.length"));
Assert.Equal(1, engine.Evaluate("emptyArray.push(1); return emptyArray.length"));

engine.SetValue("date", new JsDate(engine, new DateTime(2022, 10, 20)));
Assert.Equal(2022, engine.Evaluate("date.getFullYear()"));
}
Expand Down
Loading

0 comments on commit 553fdb8

Please sign in to comment.