Skip to content

fs watch() and watchImmediate() in iOS so slow #1823

Open
@XHanL

Description

@XHanL

it take 21s after create a file in appdata dir

Result

D1659C82B400C44D3A51EC4DDCD2BB5D

Code

import { createSignal, onCleanup, onMount } from "solid-js";
import "./App.css";
import { BaseDirectory, exists, create, readTextFile, watch, UnwatchFn, readDir, remove, watchImmediate } from "@tauri-apps/plugin-fs";

function App() {
  const [name, setName] = createSignal("");
  const [debug, setDebug] = createSignal("[debug]");
  const [log, setLog] = createSignal("[log]");
  const [error, setError] = createSignal("[error]");

  let startTime: number;
  let unwatch: Promise<UnwatchFn>;

  onMount(async () => {
    try {
      unwatch = watch(
        "./",
        (event) => {
          const elapsedTime = performance.now() - startTime;
          setLog(`Elapsed time: ${elapsedTime.toFixed(2)} ms\n` + JSON.stringify(event));
        },
        {
          baseDir: BaseDirectory.AppData,
          delayMs: 500,
          recursive: true,
        }
      );
    } catch (error) {
      setError(JSON.stringify(error));
    }
  });

  onCleanup(async () => {
    (await unwatch)();
  });

  return (
    <div class="container" style={{gap: "2px"}}>
      <p>{error()}</p>
      <p>{debug()}</p>
      <p>{log()}</p>

      <input onChange={(e) => setName(e.currentTarget.value)} placeholder="Enter a file name..." />

      <button
        onClick={async () => {
          startTime = performance.now();
          const file = await create(name(), { baseDir: BaseDirectory.AppData });
          await file.write(new TextEncoder().encode("Hello world" + new Date().toISOString()));
          await file.close();
        }}
      >
        Create
      </button>
      
      <button
        onClick={async () => {
          await remove(name(), { baseDir: BaseDirectory.AppData });
        }}
      >
        Remove
      </button>

      <button
        onClick={async () => {
          setDebug(JSON.stringify(await exists(name(), { baseDir: BaseDirectory.AppData })));
        }}
      >
        Exist
      </button>

      <button
        onClick={async () => {
          setDebug(await readTextFile(name(), { baseDir: BaseDirectory.AppData }));
        }}
      >
        Read
      </button>

      <button
        onClick={async () => {
          const list = await readDir("", { baseDir: BaseDirectory.AppData });
          setDebug(JSON.stringify(list));
        }}
      >
        List
      </button>
    </div>
  );
}

export default App;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingplatform: iosiOS specific issuesplugin: fsIncludes former "fs-extra" and "fs-watch" plugins

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions