Skip to content

Commit 6f47c17

Browse files
committed
Move dirty from Context to EagerDir
This move looks safe as dirty is only accessed in update, and only updated in writeEntry with no weird interleaving with setDir.
1 parent 5478dd1 commit 6f47c17

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

skiplang/prelude/src/skstore/Context.sk

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ mutable class Context private {
324324
mutable newDirs: SortedSet<DirName> = SortedSet[],
325325
mutable globals: SortedMap<String, File> = SortedMap[],
326326
private mutable persistents: SortedMap<String, File> = SortedMap[],
327-
private mutable dirty: SortedMap<DirName, SortedSet<Key>> = SortedMap[],
327+
private mutable dirsWithDirty: SortedSet<DirName> = SortedSet[],
328328
private mutable dirtyReaders: /* parentName => childName => keys */ SortedMap<
329329
DirName,
330330
SortedMap<DirName, SortedSet<Key>>,
@@ -435,7 +435,7 @@ mutable class Context private {
435435
newDirs => this.newDirs,
436436
globals => this.globals,
437437
persistents => this.persistents,
438-
dirty => this.dirty,
438+
dirsWithDirty => this.dirsWithDirty,
439439
dirtyReaders => this.dirtyReaders,
440440
canReuse => this.canReuse,
441441
arrowStack => this.arrowStack,
@@ -466,7 +466,7 @@ mutable class Context private {
466466
this.!newDirs = ctx.newDirs;
467467
this.!globals = ctx.globals;
468468
this.!persistents = ctx.persistents;
469-
this.!dirty = ctx.dirty;
469+
this.!dirsWithDirty = ctx.dirsWithDirty;
470470
this.!dirtyReaders = ctx.dirtyReaders;
471471
this.!canReuse = ctx.canReuse;
472472
this.!arrowStack = ctx.arrowStack;
@@ -583,7 +583,7 @@ mutable class Context private {
583583
* recomputed.
584584
*
585585
* - dirtyReaders are files that are made dirty because of a read access
586-
* - dirty are files that are made dirty because of a Map.
586+
* - dirsWithDirty are dirs containing files that are made dirty because of a Map.
587587
*/
588588
/*****************************************************************************/
589589
mutable fun updateDirtyReaders(path: Path): void {
@@ -666,11 +666,8 @@ mutable class Context private {
666666
this.!lazyGets = this.lazyGets.set(Path::create(dirName, key))
667667
}
668668

669-
mutable fun addDirty(dirName: DirName, key: Key): void {
670-
this.!dirty[dirName] = this.dirty.maybeGet(dirName) match {
671-
| None() -> SortedSet[key]
672-
| Some(set) -> set.set(key)
673-
}
669+
mutable fun addDirWithDirty(dirName: DirName): void {
670+
this.!dirsWithDirty = this.dirsWithDirty.set(dirName);
674671
}
675672

676673
mutable fun update(): void {
@@ -694,7 +691,13 @@ mutable class Context private {
694691
loop {
695692
this.toUpdate.removeMin() match {
696693
| None() ->
697-
this.!dirty = SortedMap[];
694+
for (dirName in this.dirsWithDirty) {
695+
this.unsafeMaybeGetEagerDir(dirName) match {
696+
| None() -> void
697+
| Some(dir) -> this.setDir(dir.resetDirty())
698+
}
699+
};
700+
this.!dirsWithDirty = SortedSet[];
698701
this.!dirtyReaders = SortedMap[];
699702
withPostponables = this.checkPostponables();
700703
withPre = this.updatePre();
@@ -717,7 +720,6 @@ mutable class Context private {
717720
};
718721
EagerDir::update(
719722
this,
720-
this.dirty.maybeGet(parentName),
721723
this.dirtyReaders.maybeGet(parentName),
722724
parentName,
723725
parentMaps,

skiplang/prelude/src/skstore/EagerDir.sk

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,8 @@ class EagerDir protected {
636636
childDirs: SortedSet<DirName> = SortedSet[],
637637
private slices: RangeMapList<Key, DirName> = RangeMapList[],
638638
private reducer: ?Reducer = None(),
639+
/* dirty are keys of files that are made dirty because of a Map */
640+
private dirty: SortedSet<Key> = SortedSet[],
639641
private purgeCount: Int = 0,
640642
private tombLimit: ?Tick = None(),
641643
optOnDelete: ?Postponable = None(),
@@ -1535,9 +1537,12 @@ class EagerDir protected {
15351537
}
15361538
}
15371539

1540+
fun resetDirty(): this {
1541+
this with {dirty => SortedSet[]}
1542+
}
1543+
15381544
static fun update(
15391545
context: mutable Context,
1540-
parentDirtyOpt: ?SortedSet<Key>,
15411546
contextDirtyReadersOpt: ?SortedMap<DirName, SortedSet<Key>>,
15421547
parentName: DirName,
15431548
parentMaps: Array<
@@ -1574,10 +1579,8 @@ class EagerDir protected {
15741579
})
15751580
}
15761581
};
1577-
parentDirtyOpt match {
1578-
| None() -> void
1579-
| Some(dirtyKeys) ->
1580-
keys = dirtyKeys.values();
1582+
if (!parent.dirty.isEmpty()) {
1583+
keys = parent.dirty.values();
15811584
!dirty = withRegionFold(None(), keys, dirty, (_, key, dirtyInRegion) ~> {
15821585
for (p in parentMaps) {
15831586
(_, rangeOpt, _) = p;
@@ -1768,7 +1771,8 @@ class EagerDir protected {
17681771
Some(cdata)
17691772
};
17701773

1771-
context.addDirty(this.dirName, k);
1774+
context.addDirWithDirty(this.dirName);
1775+
dirty = this.dirty.set(k);
17721776
path = Path::create(this.dirName, k);
17731777

17741778
if (this.totalSize != totalSize) {
@@ -1782,7 +1786,7 @@ class EagerDir protected {
17821786
filesPath = Path::filesTag(this.dirName);
17831787
context.updateDirtyReaders(filesPath);
17841788

1785-
!this = this with {totalSize, reducer};
1789+
!this = this with {dirty, totalSize, reducer};
17861790

17871791
context.updateDirtyReaders(path);
17881792

0 commit comments

Comments
 (0)