Add debounce to import tracking#4875
Conversation
Add steps on how to profile Skip having test-results.xml checked in.
| } | ||
|
|
||
| // Debounce every 5 seconds. We don't need that much telemetry. | ||
| @debounce(5000, true) |
There was a problem hiding this comment.
This isn't the right place for debounce and i don't think we can use this approach either.
- User opens file
a.pysaves it - Next opens file
b.pysaves it
Only file b.py gets procecssed.
#Resolved
There was a problem hiding this comment.
Yep, that's true. One message max every 5 seconds. We don't get 'every' import.
Where else would I put it? It doesn't work on the onDocumentSaved because the debounce doesn't work for the TextDocument object.
In reply to: 267895392 [](ancestors = 267895392)
There was a problem hiding this comment.
Don't you want a.py to get processed? If you do, using the debounce decorator will not work.
As mentioned with the current approach, only b.py will get processed and not a.py.
If a user opens 10 files one after another, only the last file gets processed. #Resolved
There was a problem hiding this comment.
Yep. That's on purpose. That's what the debounce will do. The other alternative is not debounce but just delay each request.
In reply to: 267904335 [](ancestors = 267904335)
There was a problem hiding this comment.
Yep. That's on purpose. That's what the debounce will do.
If you're happy with the requirements, thats fine. I'm not aware of the requirements.
To me this doesn't feel right, not processing all other files.
The other alternative is not debounce but just delay each request.
That will still not work,
ideally we need to debounce per file.
#Resolved
Codecov Report
@@ Coverage Diff @@
## master #4875 +/- ##
======================================
+ Coverage 62% 62% +1%
======================================
Files 372 372
Lines 14591 14605 +14
Branches 1153 1154 +1
======================================
+ Hits 9044 9055 +11
- Misses 5340 5343 +3
Partials 207 207 |
| 1. npm run clean <- This will clean your output directory | ||
| 1. npm run compile | ||
| 1. npm run compile-webviews | ||
| 1. Copy the 'out' directory from your source code overtop of the 'out' directory in your user/.vscode/extensions/ms-python directory |
There was a problem hiding this comment.
Confused, didn't understand where out is to be copied from and into where #Resolved
There was a problem hiding this comment.
Please note, we have source maps generated when building the extension they are just renamed from *.js.map to *.js.map.disabled. #Resolved
There was a problem hiding this comment.
I don't think the maps work in the profiler. At least I couldn't get them to work.
In reply to: 267899221 [](ancestors = 267899221)
Use lineAt instead of getText.splitLines
Implement per file timeout instead
| private getDocumentLines(document: TextDocument) : string [] { | ||
| return Array.apply(null, {length: Math.min(document.lineCount, MAX_DOCUMENT_LINES)}).map((a, i) => { | ||
| const text = document.lineAt(i).text.trim(); | ||
| if (text && text.length) { |
There was a problem hiding this comment.
You can use isEmptyOrWhitespace instead of trimming. #Resolved
|
|
||
| private getDocumentLines(document: TextDocument) : string [] { | ||
| return Array.apply(null, {length: Math.min(document.lineCount, MAX_DOCUMENT_LINES)}).map((a, i) => { | ||
| const text = document.lineAt(i).text.trim(); |
There was a problem hiding this comment.
Is it possible text is undefined? #Resolved
There was a problem hiding this comment.
Fix timeout to be when finally done typing
| @@ -18,9 +19,14 @@ import { IImportTracker } from './types'; | |||
| const ImportRegEx = /^(?!['"#]).*from\s+([a-zA-Z0-9_\.]+)\s+import.*(?!['"])|^(?!['"#]).*import\s+([a-zA-Z0-9_\., ]+).*(?!['"])/; | |||
There was a problem hiding this comment.
| const ImportRegEx = /^(?!['"#]).*from\s+([a-zA-Z0-9_\.]+)\s+import.*(?!['"])|^(?!['"#]).*import\s+([a-zA-Z0-9_\., ]+).*(?!['"])/; | |
| const ImportRegEx = /^\s*(?from|import)\s+([^.]+)/; |
This should capture only absolute imports and only the top-level package which is all we would be interested in. #WontFix
There was a problem hiding this comment.
That would miss something like
import sklearn.foo
And it would not handle the case where an import was in a string or a comment.
In reply to: 267956790 [](ancestors = 267956790)
There was a problem hiding this comment.
You're right because I forgot to strip out the trailing \s. 😄
As for missing imports in a string or comment, why would we want that? If the imports aren't being used then why would we care about that case? And that should be rare enough of a case that it wouldn't skew learning what the most popular public packages used are. #WontFix
There was a problem hiding this comment.
No I meant the opposite, your string would capture ones in a string I believe. Oh maybe it wouldn't. Let me try it.
In reply to: 267960402 [](ancestors = 267960402)
There was a problem hiding this comment.
No it does work with strings.
But makes it more difficult to parse 'from x import b' statements. I have to second parse to get rid of the 'import' value. I think I'll just leave the one I have there.
In reply to: 267961343 [](ancestors = 267961343,267960402)
| private pendingDocs = new Set<string>(); | ||
| private sentMatches: Set<string> = new Set<string>(); | ||
| // tslint:disable-next-line:no-require-imports | ||
| private hashFn = require('hash.js').sha256; |
There was a problem hiding this comment.
Any reason you aren't using HMAC? Either way you need to add a salt to the hash. #Pending
There was a problem hiding this comment.
Where would the salt be stored? Seems like just obfuscation.
In reply to: 267956915 [](ancestors = 267956915)
There was a problem hiding this comment.
If you use HMAC you can initialize it with the salt. #Pending
There was a problem hiding this comment.
I'll do that if we deem it necessary to add another layer of obfuscation. We're internally going to generate a table of known hashes, so generating the table with the salt in them shouldn't be any more work.
In reply to: 267961221 [](ancestors = 267961221)
Add steps on how to profile
Skip having test-results.xml checked in.
For #4852
package-lock.jsonhas been regenerated by runningnpm install(if dependencies have changed)