forked from klesun/ts-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
klesun#8 Try sending transpilation jobs to separate workers
For some reason it did not become faster at all, possiblyI am doing something wrong
- Loading branch information
Showing
6 changed files
with
166 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//import ParseTsModule from "./actions/ParseTsModule.js"; | ||
|
||
const main = () => { | ||
self.importScripts( | ||
'https://klesun-misc.github.io/TypeScript/lib/typescriptServices.js', | ||
'https://klesun-productions.com/entry/ts-browser/src/UrlPathResolver_sideEffects.js', | ||
'https://klesun-productions.com/entry/ts-browser/src/actions/ParseTsModule_sideEffects.js' | ||
); | ||
const org = self.org; | ||
/** @type {ts} */ | ||
const ts = self.ts; | ||
|
||
const onmessage = ({data}) => { | ||
if (data.messageType === 'parseTsModule') { | ||
const parsed = org.klesun.tsBrowser.ParseTsModule_sideEffects({ | ||
...data.messageData, ts: ts, | ||
addPathToUrl: org.klesun.tsBrowser.addPathToUrl, | ||
}); | ||
self.postMessage({ | ||
messageType: 'parseTsModule', | ||
messageData: parsed, | ||
}); | ||
} | ||
}; | ||
|
||
self.onmessage = evt => { | ||
try { | ||
onmessage(evt); | ||
} catch (exc) { | ||
self.postMessage({ | ||
messageType: 'error', | ||
messageData: { | ||
message: exc.message, | ||
stack: exc.stack, | ||
}, | ||
}); | ||
} | ||
}; | ||
}; | ||
|
||
try { | ||
main(); | ||
} catch (exc) { | ||
self.postMessage('Failed to initialize worker - ' + exc + '\n' + exc.stack); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
var org = org || {}; | ||
org.klesun = org.klesun || {}; | ||
org.klesun.tsBrowser = org.klesun.tsBrowser || {}; | ||
|
||
org.klesun.tsBrowser.addPathToUrl = (path, baseUrl) => { | ||
let result; | ||
if (path.startsWith('/') || path.match(/^https?:\/\//)) { | ||
// full path from the site root | ||
result = path; | ||
} else { | ||
const urlParts = baseUrl.split('/'); | ||
const pathParts = path.split('/'); | ||
|
||
if (urlParts.slice(-1)[0] !== '') { | ||
// does not end with a slash - script, not directory | ||
urlParts.pop(); | ||
} | ||
|
||
// getting rid of trailing slashes if any | ||
while (pathParts[0] === '') pathParts.shift(); | ||
while (urlParts.slice(-1)[0] === '') urlParts.pop(); | ||
|
||
const resultParts = [...urlParts]; | ||
for (const pathPart of pathParts) { | ||
if (pathPart === '..' && resultParts.slice(-1)[0] !== '..') { | ||
while (resultParts.slice(-1)[0] === '.') resultParts.pop(); | ||
if (resultParts.length > 0) { | ||
resultParts.pop(); | ||
} else { | ||
resultParts.push('..'); | ||
} | ||
} else if (pathPart !== '.') { | ||
resultParts.push(pathPart); | ||
} | ||
} | ||
result = resultParts.join('/') || '.'; | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
const isWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope; | ||
if (isWorker) { | ||
self.org = org; | ||
} else { | ||
window.org = org; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters