diff options
author | 2021-10-04 03:28:55 -0700 | |
---|---|---|
committer | 2021-10-04 03:28:55 -0700 | |
commit | 0eb3c1d3937aa4e45e50bebe7ef0fc0c67ce8b19 (patch) | |
tree | 7bcbd8443cae90d9e200e5347db88993168c73a3 | |
parent | cb6a1b7225055575c526ac05bcf45d8bad5ce978 (diff) | |
download | bun-0eb3c1d3937aa4e45e50bebe7ef0fc0c67ce8b19.tar.gz bun-0eb3c1d3937aa4e45e50bebe7ef0fc0c67ce8b19.tar.zst bun-0eb3c1d3937aa4e45e50bebe7ef0fc0c67ce8b19.zip |
Improve Bun's performance by 5%
By making E.Identifier not a pointer, we improve performance by 5%. Heap allocations are bad
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | packages/bun-cli/scripts/postinstall.ts | 3 | ||||
-rw-r--r-- | src/bundler.zig | 15 | ||||
-rw-r--r-- | src/defines.zig | 6 | ||||
-rw-r--r-- | src/js_ast.zig | 52 | ||||
-rw-r--r-- | src/js_parser/js_parser.zig | 15 | ||||
-rw-r--r-- | src/js_printer.zig | 7 |
7 files changed, 46 insertions, 58 deletions
@@ -161,9 +161,9 @@ release-cli-push: rm -rf $(BUN_DEPLOY_CLI) mkdir -p $(BUN_DEPLOY_CLI) cp -r packages/bun-cli $(BUN_DEPLOY_CLI) - cd $(BUN_DEPLOY_PKG); npm pack; - gh release upload $(BUN_BUILD_TAG) --clobber $(BUN_DEPLOY_CLI)/bun-cli-$(PACKAGE_JSON_VERSION).tgz - npm publish $(BUN_DEPLOY_CLI)/bun-cli-$(PACKAGE_JSON_VERSION).tgz --access=public + cd $(BUN_DEPLOY_CLI)/bun-cli; npm pack; + gh release upload $(BUN_BUILD_TAG) --clobber $(BUN_DEPLOY_CLI)//bun-cli/bun-cli-$(PACKAGE_JSON_VERSION).tgz + npm publish $(BUN_DEPLOY_CLI)/bun-cli/bun-cli-$(PACKAGE_JSON_VERSION).tgz --access=public release-bin-push: write-package-json-version rm -rf $(BUN_DEPLOY_DIR) diff --git a/packages/bun-cli/scripts/postinstall.ts b/packages/bun-cli/scripts/postinstall.ts index e0f6adf54..758174d2a 100644 --- a/packages/bun-cli/scripts/postinstall.ts +++ b/packages/bun-cli/scripts/postinstall.ts @@ -336,6 +336,7 @@ const knownUnixlikePackages: Record<string, string> = { // "android arm64 LE": "bun-cli-android-arm64", "darwin arm64 LE": "bun-cli-darwin-aarch64", "darwin x64 LE": "bun-cli-darwin-x64", + "linux x64 LE": "bun-cli-linux-x64", // "freebsd arm64 LE": "bun-cli-freebsd-arm64", // "freebsd x64 LE": "bun-cli-freebsd-64", // "openbsd x64 LE": "bun-cli-openbsd-64", @@ -344,7 +345,7 @@ const knownUnixlikePackages: Record<string, string> = { // "linux ia32 LE": "bun-cli-linux-32", // "linux mips64el LE": "bun-cli-linux-mips64le", // "linux ppc64 LE": "bun-cli-linux-ppc64le", - // "linux x64 LE": "bun-cli-linux-64", + // "sunos x64 LE": "bun-cli-sunos-64", }; diff --git a/src/bundler.zig b/src/bundler.zig index 262a22888..d1b530c82 100644 --- a/src/bundler.zig +++ b/src/bundler.zig @@ -1626,7 +1626,7 @@ pub const Bundler = struct { json_e_identifier = js_ast.E.Identifier{ .ref = Ref{ .source_index = 0, .inner_index = @intCast(Ref.Int, json_ast_symbols_list.len - 1) } }; json_e_call = js_ast.E.Call{ - .target = js_ast.Expr{ .data = .{ .e_identifier = &json_e_identifier }, .loc = logger.Loc{ .start = 0 } }, + .target = js_ast.Expr{ .data = .{ .e_identifier = json_e_identifier }, .loc = logger.Loc{ .start = 0 } }, .args = std.mem.span(&json_call_args), }; break :brk js_ast.Expr{ .data = .{ .e_call = &json_e_call }, .loc = logger.Loc{ .start = 0 } }; @@ -1746,7 +1746,7 @@ pub const Bundler = struct { var call_register = E.Call{ .target = Expr{ - .data = .{ .e_identifier = &target_identifier }, + .data = .{ .e_identifier = target_identifier }, .loc = logger.Loc{ .start = 0 }, }, .args = ®ister_args, @@ -3364,12 +3364,11 @@ pub const ResolveQueue = std.fifo.LinearFifo( std.fifo.LinearFifoBufferType.Dynamic, ); -// This is not very fast. -// The idea is: we want to generate a unique entry point per macro function export that registers the macro -// Registering the macro happens in VirtualMachine -// We "register" it which just marks the JSValue as protected. -// This is mostly a workaround for being unable to call ESM exported functions from C++. -// When that is resolved, we should remove this. +// This is not very fast. The idea is: we want to generate a unique entry point +// per macro function export that registers the macro Registering the macro +// happens in VirtualMachine We "register" it which just marks the JSValue as +// protected. This is mostly a workaround for being unable to call ESM exported +// functions from C++. When that is resolved, we should remove this. pub const MacroEntryPoint = struct { code_buffer: [std.fs.MAX_PATH_BYTES * 2 + 500]u8 = undefined, output_code_buffer: [std.fs.MAX_PATH_BYTES * 8 + 500]u8 = undefined, diff --git a/src/defines.zig b/src/defines.zig index bb5ccae3b..a17b96fe9 100644 --- a/src/defines.zig +++ b/src/defines.zig @@ -96,9 +96,7 @@ pub const DefineData = struct { }, ); } else { - var ident: *js_ast.E.Identifier = try allocator.create(js_ast.E.Identifier); - ident.ref = Ref.None; - ident.can_be_removed_if_unused = true; + const ident = js_ast.E.Identifier{ .ref = Ref.None, .can_be_removed_if_unused = true }; user_defines.putAssumeCapacity( entry.key_ptr.*, @@ -334,7 +332,7 @@ pub const Define = struct { { var global_entry = define.identifiers.getOrPutAssumeCapacity(Rewrites.global); if (!global_entry.found_existing) { - global_entry.value_ptr.* = DefineData{ .value = js_ast.Expr.Data{ .e_identifier = &globalThisIdentifier }, .original_name = Rewrites.globalThis }; + global_entry.value_ptr.* = DefineData{ .value = js_ast.Expr.Data{ .e_identifier = globalThisIdentifier }, .original_name = Rewrites.globalThis }; } } diff --git a/src/js_ast.zig b/src/js_ast.zig index acfdece68..986c3f6c7 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -1251,7 +1251,7 @@ pub const E = struct { no: ExprNodeIndex, }; - pub const Require = packed struct { + pub const Require = struct { import_record_index: u32 = 0, }; @@ -1962,12 +1962,6 @@ pub const Expr = struct { pub fn getArrow(exp: *const Expr) *E.Arrow { return exp.data.e_arrow; } - pub fn getIdentifier(exp: *const Expr) *E.Identifier { - return exp.data.e_identifier; - } - pub fn getImportIdentifier(exp: *const Expr) *E.ImportIdentifier { - return exp.data.e_import_identifier; - } pub fn getPrivateIdentifier(exp: *const Expr) *E.PrivateIdentifier { return exp.data.e_private_identifier; } @@ -2383,7 +2377,7 @@ pub const Expr = struct { return Expr{ .loc = loc, .data = Data{ - .e_identifier = Data.Store.Identifier.append(Type, st), + .e_identifier = st, }, }; }, @@ -2391,7 +2385,7 @@ pub const Expr = struct { return Expr{ .loc = loc, .data = Data{ - .e_import_identifier = Data.Store.All.append(Type, st), + .e_import_identifier = st, }, }; }, @@ -2515,7 +2509,7 @@ pub const Expr = struct { return Expr{ .loc = loc, .data = Data{ - .e_require_or_require_resolve = Data.Store.All.append(Type, st), + .e_require_or_require_resolve = st, }, }; }, @@ -2531,7 +2525,7 @@ pub const Expr = struct { return Expr{ .loc = loc, .data = Data{ - .e_require = Data.Store.All.append(Type, st), + .e_require = st, }, }; }, @@ -3109,8 +3103,8 @@ pub const Expr = struct { e_dot: *E.Dot, e_index: *E.Index, e_arrow: *E.Arrow, - e_identifier: *E.Identifier, - e_import_identifier: *E.ImportIdentifier, + e_identifier: E.Identifier, + e_import_identifier: E.ImportIdentifier, e_private_identifier: *E.PrivateIdentifier, e_jsx_element: *E.JSXElement, @@ -3123,8 +3117,8 @@ pub const Expr = struct { e_await: *E.Await, e_yield: *E.Yield, e_if: *E.If, - e_require: *E.Require, - e_require_or_require_resolve: *E.RequireOrRequireResolve, + e_require: E.Require, + e_require_or_require_resolve: E.RequireOrRequireResolve, e_import: *E.Import, e_boolean: E.Boolean, @@ -3148,7 +3142,6 @@ pub const Expr = struct { const often = 512; const medium = 256; const rare = 24; - const Identifier = NewBaseStore([_]type{E.Identifier}, 512); pub const All = NewBaseStore( &([_]type{ @@ -3156,16 +3149,14 @@ pub const Expr = struct { E.Unary, E.Binary, E.Class, - E.Boolean, - E.Super, E.New, E.Function, E.Call, E.Dot, E.Index, E.Arrow, + E.RegExp, - E.ImportIdentifier, E.PrivateIdentifier, E.JSXElement, E.Number, @@ -3175,12 +3166,9 @@ pub const Expr = struct { E.String, E.TemplatePart, E.Template, - E.RegExp, E.Await, E.Yield, E.If, - E.Require, - E.RequireOrRequireResolve, E.Import, }), 512, @@ -3195,13 +3183,11 @@ pub const Expr = struct { has_inited = true; _ = All.init(allocator); - _ = Identifier.init(allocator); } pub fn reset() void { if (disable_reset) return; All.reset(); - Identifier.reset(); } pub fn append(comptime ValueType: type, value: anytype) *ValueType { @@ -4891,8 +4877,9 @@ pub const Macro = struct { e_dot: *E.Dot, e_index: *E.Index, e_arrow: *E.Arrow, - e_identifier: *E.Identifier, - e_import_identifier: *E.ImportIdentifier, + e_identifier: E.Identifier, + e_import_identifier: E.ImportIdentifier, + e_private_identifier: *E.PrivateIdentifier, e_jsx_element: *E.JSXElement, @@ -4902,19 +4889,22 @@ pub const Macro = struct { e_string: *E.String, e_template_part: *E.TemplatePart, e_template: *E.Template, - e_reg_exp: *E.RegExp, + e_await: *E.Await, e_yield: *E.Yield, e_if: *E.If, - e_require_or_require_resolve: *E.RequireOrRequireResolve, + e_import: *E.Import, e_class: *E.Class, - e_require: *E.Require, s_import: *ImportData, s_block: *S.Block, + e_reg_exp: *E.RegExp, + e_require_or_require_resolve: E.RequireOrRequireResolve, + e_require: E.Require, + g_property: *G.Property, inline_inject: []JSNode, @@ -5905,7 +5895,7 @@ pub const Macro = struct { E.Call{ .target = Expr{ .data = .{ - .e_identifier = self.bun_identifier, + .e_identifier = self.bun_identifier.*, }, .loc = tag_expr.loc, }, @@ -5930,7 +5920,7 @@ pub const Macro = struct { E.Call{ .target = Expr{ .data = .{ - .e_identifier = self.bun_identifier, + .e_identifier = self.bun_identifier.*, }, .loc = loc, }, diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig index 5891cd17a..6acf11e6c 100644 --- a/src/js_parser/js_parser.zig +++ b/src/js_parser/js_parser.zig @@ -3599,7 +3599,7 @@ pub fn NewParser( return .forbidden; } - pub fn handleIdentifier(p: *P, loc: logger.Loc, ident: *E.Identifier, _original_name: ?string, opts: IdentifierOpts) Expr { + pub fn handleIdentifier(p: *P, loc: logger.Loc, ident: E.Identifier, _original_name: ?string, opts: IdentifierOpts) Expr { const ref = ident.ref; if ((opts.assign_target != .none or opts.is_delete_target) and p.symbols.items[ref.inner_index].kind == .import) { @@ -3639,7 +3639,9 @@ pub fn NewParser( if (_original_name) |original_name| { const result = p.findSymbol(loc, original_name) catch unreachable; - ident.ref = result.ref; + var _ident = ident; + _ident.ref = result.ref; + return p.e(_ident, loc); } return p.e(ident, loc); @@ -11039,8 +11041,9 @@ pub fn NewParser( .e_spread => |exp| { exp.value = p.visitExpr(exp.value); }, - .e_identifier => |e_| { - const is_delete_target = @as(Expr.Tag, p.delete_target) == .e_identifier and expr.data.e_identifier == p.delete_target.e_identifier; + .e_identifier => { + var e_ = expr.data.e_identifier; + const is_delete_target = @as(Expr.Tag, p.delete_target) == .e_identifier and expr.data.e_identifier.ref.eql(p.delete_target.e_identifier.ref); const name = p.loadNameFromRef(e_.ref); if (p.isStrictMode() and js_lexer.StrictModeReservedWords.has(name)) { @@ -13859,11 +13862,9 @@ pub fn NewParser( fn valueForDefine(p: *P, loc: logger.Loc, assign_target: js_ast.AssignTarget, is_delete_target: bool, define_data: *const DefineData) Expr { switch (define_data.value) { .e_identifier => { - var ident = define_data.value.e_identifier; - return p.handleIdentifier( loc, - ident, + define_data.value.e_identifier, define_data.original_name.?, IdentifierOpts{ .assign_target = assign_target, diff --git a/src/js_printer.zig b/src/js_printer.zig index 6a303903b..0a62df78b 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -734,8 +734,7 @@ pub fn NewPrinter( pub fn isUnboundEvalIdentifier(p: *Printer, value: Expr) bool { switch (value.data) { - .e_identifier => { - const ident = value.getIdentifier(); + .e_identifier => |ident| { if (ident.ref.is_source_contents_slice) return false; const symbol = p.symbols.get(p.symbols.follow(ident.ref)) orelse return false; @@ -1018,7 +1017,7 @@ pub fn NewPrinter( .e_require => |e| { if (rewrite_esm_to_cjs and p.import_records[e.import_record_index].is_bundled) { p.printIndent(); - p.printBundledRequire(e.*); + p.printBundledRequire(e); p.printSemicolonIfNeeded(); } @@ -1502,7 +1501,7 @@ pub fn NewPrinter( var wrap = false; if (p.call_target) |target| { - wrap = e.was_originally_identifier and target.e_import_identifier == expr.data.e_import_identifier; + wrap = e.was_originally_identifier and target.e_import_identifier.ref.eql(expr.data.e_import_identifier.ref); } if (wrap) { |