Repository navigation
Use 70% less memory for TokenizedLines by using a different representation - #6757
Conversation
|
Are the scope name strings in a symbol table or something, or are the strings repeated? |
|
@benogle They're stored in a symbol table on the |
This avoids creating a bunch of tokens as temporary objects since they are no longer stored.
efd70b8 to
dc47369
Compare
Use 70% less memory for TokenizedLines by using a different representation
|
🎆 |
|
@nathansobo : I'm sadly still able to reproduce the error with latex files. I'm getting a I'm currently running a build from the git. (commit: 75d02cd). Any ideas what is going wrong here? |
Thanks for reporting this issue, @winnieXY: your help is much appreciated! 🙇 Are you able to reproduce this consistently? If so, could you attach the steps here, please? Any clue to make this behavior repeatable would be really, really helpful! Thanks! |
|
Yes, I'm able to reproduce this consistently in the tex files of my PhD thesis ;( |
|
/usr/share/atom/resources/app.asar/src/tokenized-buffer.js:573 Error: Encountered an invalid scope end id. Popped -13, expected to pop -65. |
|
I found another very annoying bug. Sometimes the cursor goes mad and I'm typing somewhere else than the cursor is. this is easy reproduceable with soft wrap lines and wrap lines at 80 chars. If I type a sentence and add at the end a \textsc{ which is then automatically wrapped into the next line, the cursor is not in the position it should be. |
|
This is easy reproduceable with a very small .tex file. Do you have an emailadress than I can send you the minimal working example. |
|
@winnieXY You can always paste the example into a Gist |
|
There's something I missed in the changes to |
|
@winnieXY What LaTeX package(s) do you have installed? |
|
autocomplete-bibtex, latex and language-latex - nothing else.There are two errors. First the strange behaviour of the cursor, second the error message popping up. The second one is not reproduceable with a minimal working example, thus I thought about sending one chapter of my PhD thesis to the person working on the fix - however I do not want to make this public (as this is still very alpha and contains results which are not yet published). |
|
The first error is already reported here: #6885. Maybe it is not related to this change, I don't know |
|
Okay, I've reverted the merge in 7cb0bc3. Seems like there were at least a couple of issues I didn't detect. Thanks for the rapid feedback on these. @winnieXY can you email me the example that reproduces the issue at @kevinsawicki Just a heads-up that master is no longer blocked on this. |
…-tokens"" This reverts commit 7cb0bc3.
…-tokens"" This reverts commit 7cb0bc3.
refs atom/atom#6982 refs atom/atom#6757
There was a problem hiding this comment.
I think this is destructive change on selector if this doesn't accept .function selector anymore and we should use .meta.function instead.
This caused bug on the plugin because it uses .regexp instead of .string.regexp.
klorenz/atom-regex-railroad-diagrams#42
Is this intended change of (experimental) API?
There was a problem hiding this comment.
@ypresto You're right. Sorry about that. I switched to using ScopeSelector from first-mate without recalling that their matching criteria is stricter. Can you switch to .string.regexp until I can get a fix in today?
There was a problem hiding this comment.
OK, I already PRed that repo ;).
I think it'd better to provide backward compatibility (with deprecation warning) only if dot prefix is used.
Previously, we naively stored every token on every line as its own object, and made things even worse by storing an array of scopes on every token. This caused
TokenizedLines to consume much more memory than is strictly necessary.This PR switches
TokenizedLineto a much more compact (but also more cryptic) representation. Instead of repeating the scopes on each token, we instead represent the entire tokenized line as a nested word, which intermingles start and end tags with text much like HTML.Consider the following JavaScript fragment:
Previously, we would store this as an array of tokens, each with an array of its containing scopes:
Now this is stored more like HTML, with strings intermingled with scope start / end tags.
This may look more verbose, but it eliminates the need to repeat the same scopes on successive tokens in the same branch of the syntax tree. In actuality, the scopes are encoded as simple arrays of integers. Negative integers indicate start and end tags, with odd integers being start tags and even integers being end tags for the odd integer preceding them. Positive integers stand in for strings. The integers can be translated back to scope strings by consulting a lookup table on the grammar registry. We retain the original string and combine the two pieces of data as needed.
So in reality, the stored representation looks like this.
Measurements
Here are some heap snapshots taken with
benchmark/fixtures/huge.jsin the Atom repository. This file is just a copy of jQuery 1.7.1, but has some good examples of lines with extremely complex scope structures.First, on master:
TokenizedLineinstances consume over 27MB. The largest instance is expanded in the screenshot, where you can see the vast majority of the memory for that line being consumed by thetokensarray (~25KB). Repeat that for thousands of lines and you can see the problem.Now, the same file on this branch:
Still more memory than I'd like to consume, but much less, around 8.4MB. You can see that the
tagsarray takes up much less space than thetokensarray, but still more than it seems like it should. I can save more with typed arrays, but only about 500KB in my experiment.JS objects still seem to impose a frustrating amount of overhead. Starting to wonder if we want to drop some of our low-level storage structures to C++, but I'd rather improve the structure of this layer before contemplating that. The
TokenizedLineinstances are also now much simpler objects, meaning they terminate in primitives much more quickly. I wonder if this helps the GC in that the heap is simpler and there are fewer objects to trace. This is just speculation however.Steps
tokensarray shim in core, which creates a lot of garbage