mirror of
https://github.com/oven-sh/bun
synced 2026-02-15 21:32:05 +00:00
Update to zig 0.15.2 (#24204)
Fixes ENG-21287
Build times, from `bun run build && echo '//' >> src/main.zig && time
bun run build`
|Platform|0.14.1|0.15.2|Speedup|
|-|-|-|-|
|macos debug asan|126.90s|106.27s|1.19x|
|macos debug noasan|60.62s|50.85s|1.19x|
|linux debug asan|292.77s|241.45s|1.21x|
|linux debug noasan|146.58s|130.94s|1.12x|
|linux debug use_llvm=false|n/a|78.27s|1.87x|
|windows debug asan|177.13s|142.55s|1.24x|
Runtime performance:
- next build memory usage may have gone up by 5%. Otherwise seems the
same. Some code with writers may have gotten slower, especially one
instance of a counting writer and a few instances of unbuffered writers
that now have vtable overhead.
- File size reduced by 800kb (from 100.2mb to 99.4mb)
Improvements:
- `@export` hack is no longer needed for watch
- native x86_64 backend for linux builds faster. to use it, set use_llvm
false and no_link_obj false. also set `ASAN_OPTIONS=detect_leaks=0`
otherwise it will spam the output with tens of thousands of lines of
debug info errors. may need to use the zig lldb fork for debugging.
- zig test-obj, which we will be able to use for zig unit tests
Still an issue:
- false 'dependency loop' errors remain in watch mode
- watch mode crashes observed
Follow-up:
- [ ] search `comptime Writer: type` and `comptime W: type` and remove
- [ ] remove format_mode in our zig fork
- [ ] remove deprecated.zig autoFormatLabelFallback
- [ ] remove deprecated.zig autoFormatLabel
- [ ] remove deprecated.BufferedWriter and BufferedReader
- [ ] remove override_no_export_cpp_apis as it is no longer needed
- [ ] css Parser(W) -> Parser, and remove all the comptime writer: type
params
- [ ] remove deprecated writer fully
Files that add lines:
```
649 src/deprecated.zig
167 scripts/pack-codegen-for-zig-team.ts
54 scripts/cleartrace-impl.js
46 scripts/cleartrace.ts
43 src/windows.zig
18 src/fs.zig
17 src/bun.js/ConsoleObject.zig
16 src/output.zig
12 src/bun.js/test/debug.zig
12 src/bun.js/node/node_fs.zig
8 src/env_loader.zig
7 src/css/printer.zig
7 src/cli/init_command.zig
7 src/bun.js/node.zig
6 src/string/escapeRegExp.zig
6 src/install/PnpmMatcher.zig
5 src/bun.js/webcore/Blob.zig
4 src/crash_handler.zig
4 src/bun.zig
3 src/install/lockfile/bun.lock.zig
3 src/cli/update_interactive_command.zig
3 src/cli/pack_command.zig
3 build.zig
2 src/Progress.zig
2 src/install/lockfile/lockfile_json_stringify_for_debugging.zig
2 src/css/small_list.zig
2 src/bun.js/webcore/prompt.zig
1 test/internal/ban-words.test.ts
1 test/internal/ban-limits.json
1 src/watcher/WatcherTrace.zig
1 src/transpiler.zig
1 src/shell/builtin/cp.zig
1 src/js_printer.zig
1 src/io/PipeReader.zig
1 src/install/bin.zig
1 src/css/selectors/selector.zig
1 src/cli/run_command.zig
1 src/bun.js/RuntimeTranspilerStore.zig
1 src/bun.js/bindings/JSRef.zig
1 src/bake/DevServer.zig
```
Files that remove lines:
```
-1 src/test/recover.zig
-1 src/sql/postgres/SocketMonitor.zig
-1 src/sql/mysql/MySQLRequestQueue.zig
-1 src/sourcemap/CodeCoverage.zig
-1 src/css/values/color_js.zig
-1 src/compile_target.zig
-1 src/bundler/linker_context/convertStmtsForChunk.zig
-1 src/bundler/bundle_v2.zig
-1 src/bun.js/webcore/blob/read_file.zig
-1 src/ast/base.zig
-2 src/sql/postgres/protocol/ArrayList.zig
-2 src/shell/builtin/mkdir.zig
-2 src/install/PackageManager/patchPackage.zig
-2 src/install/PackageManager/PackageManagerDirectories.zig
-2 src/fmt.zig
-2 src/css/declaration.zig
-2 src/css/css_parser.zig
-2 src/collections/baby_list.zig
-2 src/bun.js/bindings/ZigStackFrame.zig
-2 src/ast/E.zig
-3 src/StandaloneModuleGraph.zig
-3 src/deps/picohttp.zig
-3 src/deps/libuv.zig
-3 src/btjs.zig
-4 src/threading/Futex.zig
-4 src/shell/builtin/touch.zig
-4 src/meta.zig
-4 src/install/lockfile.zig
-4 src/css/selectors/parser.zig
-5 src/shell/interpreter.zig
-5 src/css/error.zig
-5 src/bun.js/web_worker.zig
-5 src/bun.js.zig
-6 src/cli/test_command.zig
-6 src/bun.js/VirtualMachine.zig
-6 src/bun.js/uuid.zig
-6 src/bun.js/bindings/JSValue.zig
-9 src/bun.js/test/pretty_format.zig
-9 src/bun.js/api/BunObject.zig
-14 src/install/install_binding.zig
-14 src/fd.zig
-14 src/bun.js/node/path.zig
-14 scripts/pack-codegen-for-zig-team.sh
-17 src/bun.js/test/diff_format.zig
```
`git diff --numstat origin/main...HEAD | awk '{ print ($1-$2)"\t"$3 }' |
sort -rn`
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
Co-authored-by: Meghan Denny <meghan@bun.com>
Co-authored-by: tayor.fish <contact@taylor.fish>
This commit is contained in:
@@ -3138,7 +3138,7 @@ pub fn StyleSheet(comptime AtRule: type) type {
|
||||
) PrintResult(ToCssResultInternal) {
|
||||
const W = @TypeOf(writer);
|
||||
|
||||
var printer = Printer(@TypeOf(writer)).new(allocator, std.ArrayList(u8).init(allocator), writer, options, import_info, local_names, symbols);
|
||||
var printer = Printer(@TypeOf(writer)).new(allocator, std.array_list.Managed(u8).init(allocator), writer, options, import_info, local_names, symbols);
|
||||
const result = this.toCssWithWriterImpl(allocator, W, &printer, options) catch {
|
||||
bun.assert(printer.error_kind != null);
|
||||
return .{
|
||||
@@ -3208,8 +3208,8 @@ pub fn StyleSheet(comptime AtRule: type) type {
|
||||
) PrintResult(ToCssResult) {
|
||||
// TODO: this is not necessary
|
||||
// Make sure we always have capacity > 0: https://github.com/napi-rs/napi-rs/issues/1124.
|
||||
var dest = ArrayList(u8).initCapacity(allocator, 1) catch unreachable;
|
||||
const writer = dest.writer(allocator);
|
||||
var dest = std.Io.Writer.Allocating.initCapacity(allocator, 1) catch unreachable;
|
||||
const writer = &dest.writer;
|
||||
const result = switch (toCssWithWriter(
|
||||
this,
|
||||
allocator,
|
||||
@@ -3224,7 +3224,7 @@ pub fn StyleSheet(comptime AtRule: type) type {
|
||||
};
|
||||
return .{
|
||||
.result = ToCssResult{
|
||||
.code = dest.items,
|
||||
.code = dest.written(),
|
||||
.dependencies = result.dependencies,
|
||||
.exports = result.exports,
|
||||
.references = result.references,
|
||||
@@ -3490,11 +3490,11 @@ pub const StyleAttribute = struct {
|
||||
// );
|
||||
|
||||
var symbols = bun.ast.Symbol.Map{};
|
||||
var dest = ArrayList(u8){};
|
||||
const writer = dest.writer(allocator);
|
||||
var dest = std.Io.Writer.Allocating.init(allocator);
|
||||
const writer = &dest.writer;
|
||||
var printer = Printer(@TypeOf(writer)).new(
|
||||
allocator,
|
||||
std.ArrayList(u8).init(allocator),
|
||||
std.array_list.Managed(u8).init(allocator),
|
||||
writer,
|
||||
options,
|
||||
import_info,
|
||||
@@ -3507,7 +3507,7 @@ pub const StyleAttribute = struct {
|
||||
|
||||
return ToCssResult{
|
||||
.dependencies = printer.dependencies,
|
||||
.code = dest.items,
|
||||
.code = dest.written(),
|
||||
.exports = null,
|
||||
.references = null,
|
||||
};
|
||||
@@ -3705,7 +3705,7 @@ pub const ParserOptions = struct {
|
||||
warning.location.line,
|
||||
warning.location.column,
|
||||
this.allocator,
|
||||
"{}",
|
||||
"{f}",
|
||||
.{warning.kind},
|
||||
) catch unreachable;
|
||||
}
|
||||
@@ -4367,7 +4367,7 @@ pub const Parser = struct {
|
||||
.result => |t| .{ .err = start.sourceLocation().newUnexpectedTokenError(t.*) },
|
||||
.err => |e| brk: {
|
||||
if (e.kind == .basic and e.kind.basic == .end_of_input) break :brk .success;
|
||||
bun.unreachablePanic("Unexpected error encountered: {}", .{e.kind});
|
||||
bun.unreachablePanic("Unexpected error encountered: {f}", .{e.kind});
|
||||
},
|
||||
};
|
||||
this.reset(&start);
|
||||
@@ -5022,7 +5022,7 @@ const Tokenizer = struct {
|
||||
break :brk .{ .delim = '~' };
|
||||
},
|
||||
else => brk: {
|
||||
if (!std.ascii.isASCII(b)) {
|
||||
if (!std.ascii.isAscii(b)) {
|
||||
break :brk this.consumeIdentLike();
|
||||
}
|
||||
this.advance(1);
|
||||
@@ -5803,10 +5803,10 @@ const Tokenizer = struct {
|
||||
'-' => this.hasAtLeast(1) and switch (this.byteAt(1)) {
|
||||
'a'...'z', 'A'...'Z', '-', '_', 0 => true,
|
||||
'\\' => !this.hasNewlineAt(1),
|
||||
else => |b| !std.ascii.isASCII(b),
|
||||
else => |b| !std.ascii.isAscii(b),
|
||||
},
|
||||
'\\' => !this.hasNewlineAt(1),
|
||||
else => |b| !std.ascii.isASCII(b),
|
||||
else => |b| !std.ascii.isAscii(b),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5837,7 +5837,7 @@ const Tokenizer = struct {
|
||||
// rejected.
|
||||
for (0..n) |i| {
|
||||
const b = this.byteAt(i);
|
||||
std.debug.assert(std.ascii.isASCII(b) or (b & 0xF0 != 0xF0 and b & 0xC0 != 0x80));
|
||||
std.debug.assert(std.ascii.isAscii(b) or (b & 0xF0 != 0xF0 and b & 0xC0 != 0x80));
|
||||
std.debug.assert(b != '\r' and b != '\n' and b != '\x0C');
|
||||
}
|
||||
}
|
||||
@@ -6129,9 +6129,7 @@ pub const Token = union(TokenKind) {
|
||||
|
||||
pub fn format(
|
||||
this: *const Token,
|
||||
comptime _: []const u8,
|
||||
_: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
writer: *std.Io.Writer,
|
||||
) !void {
|
||||
return switch (this.*) {
|
||||
.ident => |value| try serializer.serializeIdentifier(value, writer),
|
||||
@@ -6446,12 +6444,12 @@ const Dimension = struct {
|
||||
|
||||
const CopyOnWriteStr = union(enum) {
|
||||
borrowed: []const u8,
|
||||
owned: std.ArrayList(u8),
|
||||
owned: std.array_list.Managed(u8),
|
||||
|
||||
pub fn append(this: *@This(), allocator: Allocator, slice: []const u8) void {
|
||||
switch (this.*) {
|
||||
.borrowed => {
|
||||
var list = bun.handleOom(std.ArrayList(u8).initCapacity(allocator, this.borrowed.len + slice.len));
|
||||
var list = bun.handleOom(std.array_list.Managed(u8).initCapacity(allocator, this.borrowed.len + slice.len));
|
||||
list.appendSliceAssumeCapacity(this.borrowed);
|
||||
list.appendSliceAssumeCapacity(slice);
|
||||
this.* = .{ .owned = list };
|
||||
@@ -6749,7 +6747,7 @@ pub const serializer = struct {
|
||||
'0'...'9', 'A'...'Z', 'a'...'z', '_', '-' => continue,
|
||||
// the unicode replacement character
|
||||
0 => bun.strings.encodeUTF8Comptime(0xFFD),
|
||||
else => if (!std.ascii.isASCII(b)) continue else null,
|
||||
else => if (!std.ascii.isAscii(b)) continue else null,
|
||||
};
|
||||
|
||||
try writer.writeAll(value[chunk_start..i]);
|
||||
@@ -7000,18 +6998,18 @@ pub const to_css = struct {
|
||||
local_names: ?*const LocalsResultsMap,
|
||||
symbols: *const bun.ast.Symbol.Map,
|
||||
) PrintErr![]const u8 {
|
||||
var s = ArrayList(u8){};
|
||||
errdefer s.deinit(allocator);
|
||||
const writer = s.writer(allocator);
|
||||
var s = std.Io.Writer.Allocating.init(allocator);
|
||||
errdefer s.deinit();
|
||||
const writer = &s.writer;
|
||||
const W = @TypeOf(writer);
|
||||
// PERF: think about how cheap this is to create
|
||||
var printer = Printer(W).new(allocator, std.ArrayList(u8).init(allocator), writer, options, import_info, local_names, symbols);
|
||||
var printer = Printer(W).new(allocator, std.array_list.Managed(u8).init(allocator), writer, options, import_info, local_names, symbols);
|
||||
defer printer.deinit();
|
||||
switch (T) {
|
||||
CSSString => try CSSStringFns.toCss(this, W, &printer),
|
||||
else => try this.toCss(W, &printer),
|
||||
}
|
||||
return s.items;
|
||||
return s.written();
|
||||
}
|
||||
|
||||
pub fn fromList(comptime T: type, this: []const T, comptime W: type, dest: *Printer(W)) PrintErr!void {
|
||||
|
||||
Reference in New Issue
Block a user