diff options
author | 2022-01-01 01:53:50 -0800 | |
---|---|---|
committer | 2022-01-01 01:53:50 -0800 | |
commit | a17088363f16fc72562994ed01555841c7c1b1ac (patch) | |
tree | 27cb1685eb1ce676476797f7076dd46e2bac5d9c /src/analytics/analytics_thread.zig | |
parent | 83004f0a0a51658a50499256a874558f26e09a24 (diff) | |
download | bun-a17088363f16fc72562994ed01555841c7c1b1ac.tar.gz bun-a17088363f16fc72562994ed01555841c7c1b1ac.tar.zst bun-a17088363f16fc72562994ed01555841c7c1b1ac.zip |
[bun dev] Improve filesystem watcher & HMR reliability (Linux + a little macOS)
Text editors like Replit save through atomic file updates. In an inotify filesystem watcher (Linux), that appears to be a delete followed by moving the file to the directory. Now when known files are moved into a directory, the watcher sends the file change notification to the browser(s). From there, the browser looks at it's files to determine whether or not
Additionally, if an existing HMR connection does not know about a file ID passed to it, it asks the browser to reply with the file path and then starts watching that file. This improves HMR reliabiality if Bun had been restarted but the page hadn't been restarted.
Diffstat (limited to 'src/analytics/analytics_thread.zig')
-rw-r--r-- | src/analytics/analytics_thread.zig | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/analytics/analytics_thread.zig b/src/analytics/analytics_thread.zig index c77ae4075..02ae90893 100644 --- a/src/analytics/analytics_thread.zig +++ b/src/analytics/analytics_thread.zig @@ -321,7 +321,7 @@ var counter: std.atomic.Atomic(u32) = undefined; fn start() bool { @setCold(true); - defer has_loaded = true; + has_loaded = true; counter = std.atomic.Atomic(u32).init(0); event_queue = EventQueue.init(std.heap.c_allocator); @@ -352,23 +352,26 @@ const header_entry = Headers.Kv{ }, }; +var out_buffer: MutableString = undefined; +var event_list: EventList = undefined; fn readloop() anyerror!void { defer disabled = true; Output.Source.configureNamedThread(thread, "Analytics"); defer Output.flush(); - var event_list = try default_allocator.create(EventList); - event_list.* = EventList.init(); + + event_list = EventList.init(); var headers_entries: Headers.Entries = Headers.Entries{}; headers_entries.append(default_allocator, header_entry) catch unreachable; + out_buffer = try MutableString.init(default_allocator, 64); event_list.async_http = HTTP.AsyncHTTP.init( default_allocator, .POST, URL.parse(Environment.analytics_url), headers_entries, headers_buf, - &event_list.out_buffer, + &out_buffer, &event_list.in_buffer, std.time.ns_per_ms * 10000, ) catch return; @@ -395,7 +398,6 @@ pub const EventList = struct { events: std.ArrayList(Event), async_http: HTTP.AsyncHTTP, - out_buffer: MutableString, in_buffer: MutableString, pub fn init() EventList { @@ -405,7 +407,6 @@ pub const EventList = struct { .events = std.ArrayList(Event).init(default_allocator), .in_buffer = MutableString.init(default_allocator, 1024) catch unreachable, .async_http = undefined, - .out_buffer = MutableString.init(default_allocator, 0) catch unreachable, }; } @@ -510,7 +511,7 @@ pub const EventList = struct { disabled = disabled or stuck_count > 4; this.in_buffer.reset(); - this.out_buffer.reset(); +out_buffer.reset(); if (comptime FeatureFlags.verbose_analytics) { Output.prettyErrorln("[Analytics] Sent {d} events", .{count}); |