Skip to content

Conversation

@sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Mar 24, 2023

Also, set entries to undefined rather than using the delete operator on the
handle array. Apparently using delete can lead to holes in the array which
can damage perf.

This actually revealed a hidden bug in test/other/test_dlopen_promise.c.

Split out from #19054

@sbc100 sbc100 requested review from RReverser and tlively March 24, 2023 21:10
std::shared_ptr<Directory> createDirectory(mode_t mode) override {
proxy([](auto ctx) { _wasmfs_opfs_init_root_directory(ctx.ctx); });
return std::make_shared<OPFSDirectory>(mode, this, 0, proxy);
return std::make_shared<OPFSDirectory>(mode, this, 1, proxy);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wonder if we should have _wasmfs_opfs_init_root_directory return the id here? Would that be easy?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that would be easy.

@RReverser
Copy link
Collaborator

Oh nice. FWIW having 0 reserved also allows to simplify allocate a bit:

    this.allocate = function(handle) {
      let id = this.freelist.pop() || this.allocated.length;
      this.allocated[id] = handle;
      return id;
    };

@sbc100
Copy link
Collaborator Author

sbc100 commented Mar 24, 2023

this.allocated[id] = handle;

Oh nice!

Also, set entries to `undefined` rather than using the `delete` operator
on the handle array.  Apparently using `delete` can lead to holes in the
array which can damage perf.

Reserving 0 also allows us to simplify the allocate function a little.

This actually revealed a hidden bug in test/other/test_dlopen_promise.c.

Split out from #19054
@sbc100 sbc100 force-pushed the reserve_zero_handle branch from 4c5ba63 to e5470d3 Compare March 24, 2023 22:45
@sbc100 sbc100 merged commit 376c6ff into main Mar 25, 2023
@sbc100 sbc100 deleted the reserve_zero_handle branch March 25, 2023 00:35
Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

LGTM % comments

$HandleAllocator__docs: '/** @constructor */',
$HandleAllocator: function() {
this.allocated = [];
// Reserve slot 0 so that 0 is always and invalid handle
Copy link
Member

Choose a reason for hiding this comment

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

"and" => "an"

if (wasmfsOPFSDirectoryHandles.allocated.length == 0) {
// allocated.length start of as 1 since 0 is a reserved handle
if (wasmfsOPFSDirectoryHandles.allocated.length == 1) {
// Directory 0 is reserved as the root
Copy link
Member

Choose a reason for hiding this comment

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

This comment needs to be updated to say "Directory 1"

std::shared_ptr<Directory> createDirectory(mode_t mode) override {
proxy([](auto ctx) { _wasmfs_opfs_init_root_directory(ctx.ctx); });
return std::make_shared<OPFSDirectory>(mode, this, 0, proxy);
return std::make_shared<OPFSDirectory>(mode, this, 1, proxy);
Copy link
Member

Choose a reason for hiding this comment

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

Yes, that would be easy.

@sbc100
Copy link
Collaborator Author

sbc100 commented Mar 27, 2023

Oops, we make a followup with feedback

sbc100 added a commit that referenced this pull request Mar 27, 2023
sbc100 added a commit that referenced this pull request Mar 27, 2023
RReverser pushed a commit that referenced this pull request Mar 29, 2023
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.

4 participants