Skip to content

Commit

Permalink
Merge pull request #898 from stanford-oval/wip/remove-mmap-io
Browse files Browse the repository at this point in the history
Remove mmap-io which constantly causing issues
  • Loading branch information
Silei Xu committed Mar 30, 2022
2 parents 77295b4 + 8e83a6a commit bfe0760
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 61 deletions.
20 changes: 1 addition & 19 deletions lib/prediction/exact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,7 @@ export default class ExactMatcher {
}

async load(filename : string) {
let buffer;
try {
const mmap = (await import('mmap-io')).default;
const fd = await pfs.open(filename, 'r');
const stats = await fd.stat();
buffer = mmap.map(Math.ceil(stats.size / mmap.PAGESIZE) * mmap.PAGESIZE,
mmap.PROT_READ, mmap.MAP_SHARED | mmap.MAP_POPULATE, fd.fd, 0, mmap.MADV_RANDOM);

// we created the mapping, so we can close the file and remove it - the kernel
// keeps a reference to it
// at the next load, we'll overwrite _btrie, which will cause the buffer to go unreferenced
// later, the GC will release buffer, unmap it, and _only then_ will the file actually be
// closed and deleted
await fd.close();
} catch(e) {
if (e.code !== 'MODULE_NOT_FOUND')
throw e;
buffer = await pfs.readFile(filename);
}
const buffer = await pfs.readFile(filename);
this._btrie = new BTrie(buffer);

// assume that the binary file contains all modifications made afterwards, and clear the trie
Expand Down
41 changes: 0 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"js-yaml": "^4.1.0",
"lice-js": "^0.2.0",
"mime": "^3.0.0",
"mmap-io": "^1.1.7",
"morgan": "^1.9.1",
"node-gettext": "^3.0.0",
"nodemailer": "^6.7.2",
Expand Down

0 comments on commit bfe0760

Please sign in to comment.