LaTeX.js
LaTeX.js copied to clipboard
Combine all resource into one
I'm working on the postcss branch in this repository. Since my work is finally done, you can try it now. As good news, we don't need to http request more than once. As bad news, bundle size is increased up to 17MB.
Because we are originally downloading 17MB to render contents, I think this is not so serious problem in the browser. Node.js, however, faults on the test every time. require crushes while loading a large file.
I propose you two ways.
- Give up to combine resources
- Create a new entry point for node.js
Which do you prefer?
Hm. Giving up is never the best solution :-p I like your idea, so giving the CLI an inline option to create the HTML with all assets included would be great.
So what do you mean with the second way, what is a new entry point? And what exactly is the crash error? Node should not have a limit when loading files...
Okay, I'll add a CLI option like --standalone.
The error log is a following.
d172-127:LaTeX.js fgborges$ yarn test
yarn run v1.15.2
$ mocha test/*.ls;
LaTeX.js API test
1) node API
✓ browser API
2) web component API
LaTeX.js CLI test
✓ get version (1000ms)
✓ get help (968ms)
✓ error on unknown option (925ms)
✓ error on incorrect use (1514ms)
- TODO: parsing bug in commander
Error: Reached I/O timeout
3) default translation
✓ return only the body (1065ms)
✓ include custom macros (1250ms)
LaTeX.js fixtures
boxes.tex
- ** minipage
- ** parbox - simple alignment
- - screenshot
✓ ** parbox - alignment with a given height (81ms)
<--- Last few GCs --->
[7384:0x1020ad000] 82523 ms: Scavenge 1339.4 (1422.6) -> 1338.7 (1423.6) MB, 3.4 / 0.0 ms (average mu = 0.183, current mu = 0.108) allocation failure
[7384:0x1020ad000] 82533 ms: Scavenge 1339.6 (1423.6) -> 1338.9 (1424.1) MB, 3.9 / 0.0 ms (average mu = 0.183, current mu = 0.108) allocation failure
[7384:0x1020ad000] 82544 ms: Scavenge 1339.8 (1424.1) -> 1339.1 (1424.6) MB, 3.5 / 0.0 ms (average mu = 0.183, current mu = 0.108) allocation failure
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x1726b7d4fc7d]
Security context: 0x32690d61d9b1 <JSObject>
1: /* anonymous */ [0x32699702b909] [/Users/fgborges/LaTeX.js/node_modules/svgdom/class/Node.js:~589] [pc=0x1726b7dca745](this=0x3269dbb02201 <SAXParser map = 0x32690a3027a1>,0x3269b9f07841 <String[1]: K>)
2: write [0x3269ab61a0c9] [/Users/fgborges/LaTeX.js/node_modules/sax/lib/sax.js:~965] [pc=0x1726b7dd0866](this=0x3269dbb02201 <SAXParser map = 0x32690...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Writing Node.js report to file: report.20190707.065446.7384.001.json
Node.js report completed
1: 0x100064183 node::Abort() [/usr/local/Cellar/node/11.11.0/bin/node]
2: 0x1000647f1 node::OnFatalError(char const*, char const*) [/usr/local/Cellar/node/11.11.0/bin/node]
3: 0x10017d12f v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/Cellar/node/11.11.0/bin/node]
4: 0x10017d0d0 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/Cellar/node/11.11.0/bin/node]
5: 0x100439f30 v8::internal::Heap::UpdateSurvivalStatistics(int) [/usr/local/Cellar/node/11.11.0/bin/node]
6: 0x10043b971 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [/usr/local/Cellar/node/11.11.0/bin/node]
7: 0x1004392b7 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/Cellar/node/11.11.0/bin/node]
8: 0x1004380a5 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/Cellar/node/11.11.0/bin/node]
9: 0x10043ff69 v8::internal::Heap::AllocateRawWithLightRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/Cellar/node/11.11.0/bin/node]
10: 0x10043ffb8 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/Cellar/node/11.11.0/bin/node]
11: 0x1004207e7 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/Cellar/node/11.11.0/bin/node]
12: 0x1005fd2ed v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/Cellar/node/11.11.0/bin/node]
13: 0x1726b7d4fc7d
error Command failed with signal "SIGABRT".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I means we should make two files latex.umd.js and latex-standalone.umd.js. One is classical version for node.js . Another is bundled version for the browser.
Oh, I see.... "JavaScript heap out of memory" means we should probably simply run node with node --max-old-space-size=8192.
Making two files is good, but I would have done it exactly the other way around: the browser is loading the stuff from a webserver anyway, and it is faster if it can delay loading the fonts. But with node.js, we can output a single file for distribution. Hm. Not sure yet what to do.