'Deno Slow FS Performance

I've noticed a very noticeably slow performance in reading files in deno, I'm afraid I might be doing it wrong. (kinda stupid?)

const file = Deno.readFileSync(path)

any suggestions? or other faster ways? should I use Deno.run instead? what are the pros and cons of Deno.run in your experience?

Update #1:

I found this module using streams in which it give some more speed, but compared to bash it's very slow:

$ time deno run --allow-read https://deno.land/[email protected]/examples/cat.ts movie.mp4 |  wc -l
4066379

real    0m1.890s
user    0m1.608s
sys     0m1.355s

$ time cat movie.mp4 | wc -l
4066379

real    0m0.295s
user    0m0.098s
sys     0m0.372s

$ du -sh movie.mp4 
995M    movie.mp4

Update #2:

Due to the worries of the network speed and Deno launch speed, I made this script where it has them both running respectively:

import {
  copy,
  writeAllSync,
} from "https://deno.land/[email protected]/streams/conversion.ts";

const filenames = "movie.mp4";

//########## DENO ############

const before1 = performance.now();

const file = await Deno.open(filenames);
await copy(file, Deno.stdout);
file.close();

const after1 = performance.now() - before1;

const text1 = new TextEncoder().encode(after1.toString() + "\n");
writeAllSync(Deno.stderr, text1);

//########## CMD ############

const before2 = performance.now();

const p = Deno.run({
  cmd: ["cat", `${filenames}`],
});

await p.status()

const after2 = performance.now() - before2;

const text2 = new TextEncoder().encode(after2.toString() + "\n");
writeAllSync(Deno.stderr, text2);

Results in best case:

$ deno run --allow-run --allow-read test.ts >/dev/null
636
82


Solution 1:[1]

Until this moment of writing this comment, I'd like to mention there are no solutions regarding this well-known issue in deno.

There are multiple opened issues in denoland/deno Repository. If there are any updates, I will post an update.

To mention few:

#13720

#10157

#803

#246

#13608

If you find any, please let me know.

Thanks.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1