Closed Bug 1231711 Opened 9 years ago Closed 2 years ago

[meta] Port OS.File to C++

Categories

(Toolkit Graveyard :: OS.File, enhancement)

enhancement

Tracking

(Performance Impact:low)

RESOLVED FIXED
Performance Impact low

People

(Reporter: Yoric, Assigned: barret, Mentored)

References

(Depends on 2 open bugs)

Details

(Keywords: meta, perf:responsiveness)

Attachments

(3 obsolete files)

Putting this on the radar. Would solve bug 1208199 which has baffled us (in its previous incarnations) for 1-2 years, plus save memory.
Better for projects using rust to depend on the 'oxidation' build support bug, instead of blocking it.
No longer blocks: oxidation
Depends on: oxidation
How much of the complexity of OS.file is the implementation of all the IO (managing file descriptors etc), and how much of it is exposing a nice API to WebIDL (managing promises, etc)? If we do this in Rust, we're still going to need to implement the API layer in C++.
Frankly, most of the complexity is exposing the nice API to WebIDL. That's the main thing that has refrained me from working on this so far. Well, that and the chronic lack of time.
(In reply to David Teller [:Yoric] (please use "needinfo") from comment #3) > Frankly, most of the complexity is exposing the nice API to WebIDL. That's > the main thing that has refrained me from working on this so far. Well, that > and the chronic lack of time. In that case, this bug is tantamount to "Port OS.File to C++". Is that something we actually want to do?
It might be something we want to do, I'm not sure. Also, this bug can also be "once Rust and WebIDL can speak natively together in Gecko, port OS.File to Rust".
(In reply to David Teller [:Yoric] (please use "needinfo") from comment #5) > It might be something we want to do, I'm not sure. Also, this bug can also > be "once Rust and WebIDL can speak natively together in Gecko, port OS.File > to Rust". Except that we have no intention of making Rust and WebIDL speak natively together in the foreseeable future, which is why I think this bug is as-filed is kinda misleading.
Summary: Port OS.File to Rust → Port OS.File to C++
(Unless there is some large surface of IO machinery that we would write in Rust that doesn't already exist in Gecko C++).
No longer depends on: oxidation

Adding to the qf triage queue as this may have perf improvement.

Whiteboard: [qf]

I'd have thought that the slow bit would be the code that hits the disk, not the JS interpreter.

So I would argue that we should collect some evidence that OS.File is slow because it's in JS before we commit to rewriting it in native code. Is it possible to prove that by collecting profiles?

Whiteboard: [qf] → [qf:p3:responsiveness]

(In reply to Chris Pearce [:cpearce (GMT+13)] from comment #9)

I'd have thought that the slow bit would be the code that hits the disk, not the JS interpreter.

So I would argue that we should collect some evidence that OS.File is slow because it's in JS before we commit to rewriting it in native code. Is it possible to prove that by collecting profiles?

When we tested, OS.File was slow (at least during startup) because loading the JS code from a worker required hitting the disk while everything else in Firefox was busy doing the same thing, to load modules, UI resources, etc. This caused serious cache contention which, when we measured with Telemetry, could last more than 5 seconds for ~5 percentiles of users.

We got out of this by fast-pathing a few critical bits of OS.File into C++, which means that some of the code of OS.File is implemented twice, once in fast-path, once in slow-path. Not the nicest/most reliable of things, especially in presence of concurrency.

No longer blocks: 1549386
Attached file Bug 1231711: Add WebIDL API for OS.File replacement (obsolete) (deleted) —
Attached file Bug 1231711: Add C++ headers for IOUtils (obsolete) (deleted) —

Depends on D76743

Attached file Bug 1231711: Stub out C++ implementation for IOUtils (obsolete) (deleted) —

Depends on D76905

Assignee: nobody → mail
Mentor: brennie
Depends on: 1641699
Summary: Port OS.File to C++ → [meta] Port OS.File to C++

Turning this into a meta bug to track my work on this port.

Comment on attachment 9151573 [details]
Bug 1231711: Add WebIDL API for OS.File replacement

Revision D76743 was moved to bug 1641699. Setting attachment 9151573 [details] to obsolete.

Attachment #9151573 - Attachment is obsolete: true

Comment on attachment 9151857 [details]
Bug 1231711: Add C++ headers for IOUtils

Revision D76905 was moved to bug 1641699. Setting attachment 9151857 [details] to obsolete.

Attachment #9151857 - Attachment is obsolete: true

Comment on attachment 9152494 [details]
Bug 1231711: Stub out C++ implementation for IOUtils

Revision D77317 was moved to bug 1641699. Setting attachment 9152494 [details] to obsolete.

Attachment #9152494 - Attachment is obsolete: true
Depends on: 1642454

I'm working on an implementation of async read/write methods in bug 1642454, and so far have calls working from the main thread and (async) web workers. I'd like to keep the API as simple as possible. Will just exposing async methods will be sufficient, or is there a convincing reason to also have synchronous equivalents?

E.g. for a read method.

Promise<Uint8Array> read(DOMString path, optional long maxBytes);
UintArray readSync(DOMString pat, optional long maxBytes); // Will I need something like this?
Flags: needinfo?(dteller)

For L10nRegistry rewrite to Rust I'd like to use this and I'll need sync I/O.

I understand it it's not the goal of this patchset and will understand if you decide it's out of scope but just providing a use case.

(In reply to Keefer Rourke from comment #18)

I'm working on an implementation of async read/write methods in bug 1642454, and so far have calls working from the main thread and (async) web workers. I'd like to keep the API as simple as possible. Will just exposing async methods will be sufficient, or is there a convincing reason to also have synchronous equivalents?

E.g. for a read method.

Promise<Uint8Array> read(DOMString path, optional long maxBytes);
UintArray readSync(DOMString pat, optional long maxBytes); // Will I need something like this?

Not having a sync version will make the workers a bit trickier to rewrite, but I think we should be able to manage on this front.

Now, as mentioned by zbraniecki, sync I/O for threads would be useful, but I think it can wait for a followup.

Flags: needinfo?(dteller)
Depends on: 1650227
Depends on: 1653001
Depends on: 1653003
Depends on: 1653985
Depends on: 1655460
Depends on: 1655461
Depends on: 1657647
Depends on: 1660328
No longer blocks: 1613705
Depends on: 1660835
Depends on: 1660843

Hi, is it possible to append to a file with IOUtils? I'm asking because in Thunderbird, we save mail content and attachments to a tmp file before sending, we don't want to hold them all in memory, so we use OS.File.open and write out piece by piece. Since IOUtils don't expose file handler, and there isn't an appendMode in WriteAtomicOptions, I can't figure out how to do appending with IOUtils.

Depends on: 1663707

:rnons, not yet, but I've filed bug 1663707 to add support for this.

Assignee: mail → brennie
No longer depends on: 1663707
Depends on: 1663707
Blocks: 1671035
No longer blocks: 1671035
Depends on: 1671035
Depends on: 1676942
Depends on: 1678415
Depends on: 1678471
Depends on: 1679704
Depends on: 1680103
Depends on: 1673019
Depends on: 1672431
Depends on: 1679675
Depends on: 1684999
Depends on: 1723082
Type: defect → enhancement
Depends on: 1741920

Can the winAttributes property be ported to IOUtils.setPermissions? Right now one can use the following to make a temporary file hidden on windows, while prefacing its filename with a dot to hide it for most linux users. OS.File.setPermissions(file, { winAttributes: { hidden: true } });

But I'm pretty sure the IOUtils version only supports the unixMode and unixHonorUmask properties. The winAttributes property is also missing from the table in the migration documentation, which makes it look like it's a 1-for-1 substitute, but I don't think it is. I don't know of any mozilla products that currently need to use this feature outside of test files, but I am using it for autoconfig scripts and enterprise deployments may also use it to set the "system" and "hidden" file attributes. So I will have to keep using OS.File for that particular method until it's ported

Depends on: 1743404

aminomancer, I've filed bug 1743404 for that purpose.

Thanks! Looks good

Severity: normal → --
Depends on: 1736331
Performance Impact: --- → P3
Whiteboard: [qf:p3:responsiveness]
Blocks: 1776480
Depends on: 1796835
Depends on: 1797358
Depends on: 1801497
No longer depends on: 1801497
Depends on: 1819253

Bug 1737308 has closed and OS.File is pending removal in bug 1776480. We can consider this complete.

Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Product: Toolkit → Toolkit Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: