Skip to content

Conversation

@alexlamsl
Copy link
Contributor

No description provided.

// }

pub fn addEntry(dir: *DirEntry, entry: std.fs.IterableDir.Entry, allocator: std.mem.Allocator, comptime Iterator: type, iterator: Iterator) !void {
var _kind: Entry.Kind = undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can tell this is some of the earliest code in bun because i did not know zig very well

dir_entries_option = rfs.entries.put(&cached_dir_entry_result, .{
.entries = Fs.FileSystem.DirEntry.init(dir_path),
.entries = Fs.FileSystem.DirEntry.init(
Fs.FileSystem.DirnameStore.instance.append(string, dir_path) catch unreachable,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are few cases where we need to clone this. The caller already cloned it except for the case you're running into, which has to do with automatic package installs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay let me look into that a bit more 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a debug assertion which checks:

Fs.FileSystem.DirnameStore.instance.isSliceInBuffer(dir_path) or bun.isHeapMemory(dir_path)

Then we can find the callers of this function which are not cloning the dir name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is only one user for this function:

if (r.dirInfoForResolution(dir_path_for_resolution, resolved_package_id)) |dir_info_to_use_| {

string of which is supplied by PackageManager.pathForResolution():
const dir_path_for_resolution = manager.pathForResolution(resolved_package_id, resolution, &path_in_global_disk_cache_buf) catch |err| {

which is using a threadlocal buffer:
threadlocal var path_in_global_disk_cache_buf: [bun.MAX_PATH_BYTES]u8 = undefined;

... doesn't look very cloned to me 😅

@Jarred-Sumner Jarred-Sumner merged commit 8b4e58f into oven-sh:main Feb 12, 2023
@Jarred-Sumner
Copy link
Collaborator

Thank you

@alexlamsl alexlamsl deleted the dirInfoForResolution branch February 12, 2023 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants