Skip to content

Commit

Permalink
Reduce memory usage of fs.readdir withFileTypes (#16897)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored Jan 31, 2025
1 parent 61bf221 commit 212944a
Show file tree
Hide file tree
Showing 11 changed files with 825 additions and 154 deletions.
378 changes: 378 additions & 0 deletions .cursor/rules/javascriptcore-class.mdc

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion src/bun.js/base.zig
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ pub fn toJS(globalObject: *JSC.JSGlobalObject, comptime ValueType: type, value:
},
JSC.JSValue => return if (Type != ValueType) value.* else value,

inline []const u16, []const u32, []const i16, []const i8, []const i32, []const f32 => {
var array = JSC.JSValue.createEmptyArray(globalObject, value.len);
for (value, 0..) |item, i| {
array.putIndex(
globalObject,
@truncate(i),
JSC.jsNumber(item),
);
}
return array;
},

else => {

// Recursion can stack overflow here
Expand All @@ -80,7 +92,7 @@ pub fn toJS(globalObject: *JSC.JSGlobalObject, comptime ValueType: type, value:

var array = JSC.JSValue.createEmptyArray(globalObject, value.len);
for (value, 0..) |*item, i| {
const res = toJS(globalObject, *const Child, item, lifetime);
const res = toJS(globalObject, *Child, item, lifetime);
if (res == .zero) return .zero;
array.putIndex(
globalObject,
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/bindings/JSX509CertificatePrototype.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class VM;

namespace Bun {

class JSX509CertificatePrototype final : public JSC::JSObject {
class JSX509CertificatePrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSObject;
using Base = JSC::JSNonFinalObject;
static constexpr unsigned StructureFlags = Base::StructureFlags;

static JSX509CertificatePrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
Expand Down
Loading

0 comments on commit 212944a

Please sign in to comment.