Skip to content

Commit

Permalink
Add unstable_preferTreeFS to use TreeFS without enabling symlinks
Browse files Browse the repository at this point in the history
Summary:
This allows the use of the new symlink-supporting prefix-tree `FileSystem` implementation, `TreeFS` *without* enabling symlinks.

The main purpose of this is to allow like-for-like performance comparisons of operations at this level - in particular, startup involving assembling the tree, and resolution under the new `exists` implementation.

Because `HasteFS` and `TreeFS` should have identical outputs on regular files, this setting is *not* a cache key component (unlike `resolver.unstable_enableSymlinks`).

Reviewed By: motiz88

Differential Revision: D43539702

fbshipit-source-id: 92639845f42d6c7a3d626de9853c9c360b45367a
  • Loading branch information
robhogan authored and facebook-github-bot committed Feb 27, 2023
1 parent 69c8fc7 commit 3bef954
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ Object {
"interval": 30000,
"timeout": 5000,
},
"unstable_preferTreeFS": false,
"watchman": Object {
"deferStates": Array [
"hg.update",
Expand Down Expand Up @@ -347,6 +348,7 @@ Object {
"interval": 30000,
"timeout": 5000,
},
"unstable_preferTreeFS": false,
"watchman": Object {
"deferStates": Array [
"hg.update",
Expand Down Expand Up @@ -525,6 +527,7 @@ Object {
"interval": 30000,
"timeout": 5000,
},
"unstable_preferTreeFS": false,
"watchman": Object {
"deferStates": Array [
"hg.update",
Expand Down Expand Up @@ -703,6 +706,7 @@ Object {
"interval": 30000,
"timeout": 5000,
},
"unstable_preferTreeFS": false,
"watchman": Object {
"deferStates": Array [
"hg.update",
Expand Down
7 changes: 4 additions & 3 deletions packages/metro-config/src/configTypes.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,16 @@ type SymbolicatorConfigT = {

type WatcherConfigT = {
additionalExts: $ReadOnlyArray<string>,
watchman: {
deferStates: $ReadOnlyArray<string>,
},
healthCheck: {
enabled: boolean,
interval: number,
timeout: number,
filePrefix: string,
},
unstable_preferTreeFS: boolean,
watchman: {
deferStates: $ReadOnlyArray<string>,
},
};

export type InputConfigT = $Shape<{
Expand Down
7 changes: 4 additions & 3 deletions packages/metro-config/src/defaults/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,16 @@ const getDefaultValues = (projectRoot: ?string): ConfigT => ({
},
watcher: {
additionalExts,
watchman: {
deferStates: ['hg.update'],
},
healthCheck: {
enabled: false,
filePrefix: '.metro-health-check',
interval: 30000,
timeout: 5000,
},
unstable_preferTreeFS: false,
watchman: {
deferStates: ['hg.update'],
},
},
cacheStores: [
new FileStore({
Expand Down
19 changes: 12 additions & 7 deletions packages/metro-file-map/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ export type InputOptions = $ReadOnly<{
dependencyExtractor?: ?string,
hasteImplModulePath?: ?string,

cacheManagerFactory?: ?CacheManagerFactory,
console?: Console,
healthCheck: HealthCheckOptions,
maxWorkers: number,
perfLoggerFactory?: ?PerfLoggerFactory,
resetCache?: ?boolean,
maxWorkers: number,
throwOnModuleCollision?: ?boolean,
unstable_preferTreeFS?: ?boolean,
useWatchman?: ?boolean,
watchmanDeferStates?: $ReadOnlyArray<string>,
watch?: ?boolean,
console?: Console,
cacheManagerFactory?: ?CacheManagerFactory,

healthCheck: HealthCheckOptions,
watchmanDeferStates?: $ReadOnlyArray<string>,
}>;

type HealthCheckOptions = $ReadOnly<{
Expand All @@ -120,6 +120,7 @@ type InternalOptions = {
resetCache: ?boolean,
maxWorkers: number,
throwOnModuleCollision: boolean,
unstable_preferTreeFS: boolean,
useWatchman: boolean,
watch: boolean,
watchmanDeferStates: $ReadOnlyArray<string>,
Expand Down Expand Up @@ -312,6 +313,7 @@ export default class HasteMap extends EventEmitter {
perfLoggerFactory: options.perfLoggerFactory,
resetCache: options.resetCache,
throwOnModuleCollision: !!options.throwOnModuleCollision,
unstable_preferTreeFS: !!options.unstable_preferTreeFS,
useWatchman: options.useWatchman == null ? true : options.useWatchman,
watch: !!options.watch,
watchmanDeferStates: options.watchmanDeferStates ?? [],
Expand Down Expand Up @@ -359,7 +361,10 @@ export default class HasteMap extends EventEmitter {
const rootDir = this._options.rootDir;
const fileData = initialData.files;
this._startupPerfLogger?.point('constructFileSystem_start');
const FileSystem = this._options.enableSymlinks ? TreeFS : HasteFS;
const useTreeFS =
this._options.enableSymlinks || this._options.unstable_preferTreeFS;
this._startupPerfLogger?.annotate({bool: {useTreeFS}});
const FileSystem = useTreeFS ? TreeFS : HasteFS;
const fileSystem = new FileSystem({
files: fileData,
rootDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function createHasteMap(
rootDir: config.projectRoot,
roots: config.watchFolders,
throwOnModuleCollision: options?.throwOnModuleCollision ?? true,
unstable_preferTreeFS: config.watcher.unstable_preferTreeFS,
useWatchman: config.resolver.useWatchman,
watch: options?.watch == null ? !ci.isCI : options.watch,
watchmanDeferStates: config.watcher.watchman.deferStates,
Expand Down

0 comments on commit 3bef954

Please sign in to comment.