{"id":22013951,"url":"https://github.com/pmuellr/making-your-javascript-debuggable","last_synced_at":"2025-10-07T00:33:34.549Z","repository":{"id":66666029,"uuid":"45445561","full_name":"pmuellr/making-your-JavaScript-debuggable","owner":"pmuellr","description":"samples for the \"making your JavaScript debuggable\" preso","archived":false,"fork":false,"pushed_at":"2015-11-03T06:11:31.000Z","size":136,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T08:29:56.465Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pmuellr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-03T06:08:13.000Z","updated_at":"2015-11-18T18:32:14.000Z","dependencies_parsed_at":"2023-02-25T06:30:38.501Z","dependency_job_id":null,"html_url":"https://github.com/pmuellr/making-your-JavaScript-debuggable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pmuellr/making-your-JavaScript-debuggable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmuellr%2Fmaking-your-JavaScript-debuggable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmuellr%2Fmaking-your-JavaScript-debuggable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmuellr%2Fmaking-your-JavaScript-debuggable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmuellr%2Fmaking-your-JavaScript-debuggable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pmuellr","download_url":"https://codeload.github.com/pmuellr/making-your-JavaScript-debuggable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmuellr%2Fmaking-your-JavaScript-debuggable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278703580,"owners_count":26031204,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-30T03:25:39.338Z","updated_at":"2025-10-07T00:33:34.513Z","avatar_url":"https://github.com/pmuellr.png","language":"JavaScript","readme":"making your JavaScript debuggable\n================================================================================\n\nSome samples to go with the presentation [making your JavaScript debuggable][1].\n\nThe samples are in the subdirectories; each subdirectory contains a \"broken\"\nversion of a program, and a \"fixed\" version of a program.  The context here is\nthat \"broken\" means \"difficult to debug\" and \"fixed\" means \"easier to debug\".\n\nThese samples are all executable, using hash-bang syntax, and assume that you're\nusing [N|Solid](https://nodesource.com/products/nsolid) to run the program,\nso that you can generate CPU profiles and heap snapshots from the\nN|Solid Console.\n\n\nanon-stack-traces\n--------------------------------------------------------------------------------\n\nOften when debugging we are offered stack traces of our execution profile,\neither in exception stack traces, or using the built-in v8 CPU profiler.\n\nIn this case, running the broken file under the v8 CPU profile, you see no named\nfunctions in your own code, making it a bit of a mystery as to what code is\nactually running at specific stack trace entries.\n\nRunning the fixed version, where all the functions are named, is much more\nuseful - you'll see a reasonable name instead of \"anonymous\" for all the\nprograms functions in the stack traces.\n\n\ninlining\n--------------------------------------------------------------------------------\n\nThere's a great feature in v8 called \"inlining\".  For functions whose source is\n\"small\" (default 600 bytes), v8 will attempt to inline the function, as it gets\nused a lot, in the functions that it's called from.  \n\nUnfortunately, this can lead to confusing situations when profiling your code,\nif you notice some interesting hot spot in a profile, but the stack looks like\nit's missing entries.  It might be!  Some of those missing call stacks might not\nbe call stacks anymore - the functions might have been inlined!\n\nTo restore a bit of order, you can use the Node.js option `--nouse_inlining`,\nwhich is actually one of the special v8 options you can use with Node.js.  To\nsee the complete list, run `node --v8-options`.\n\nIf you run a CPU profile on the broken file, you are likely to see only the `a()`\nand maybe `b()` functions in the stack traces.  'c()', 'd()', 'e()', and 'f()'\nare gone.\n\nIf you run a CPU profile on the fixed file, you'll see all the entries.\n\n\ntagging\n--------------------------------------------------------------------------------\n\nAnother great v8 feature is heap snapshots.  A heap snapshot provides a\ndescription of all the JavaScript objects currently allocated in your program.\nOne of the downsides of heap snapshots is that the best way to navigate through\nthem is via named classes.  The problem is that, for many Node.js APIs - both\ncore and 3rd party, classes might be in use, but you may have no idea what\nthe class names are.\n\nThe program in this case is a web server that leaks `request` objects supplied\nby the `http` module.  If you run the broken version, send it some requests\nwith the `ab` command it suggests, and the do a heap snapshot, you'll see\nthe leak.  If you know where to look.  Did you know `request` objects are\ninstances of `IncomingMessage`?\n\nTo help debug issues like this, you can add a named \"tag\" object to the\nobjects you think might be leaking.  The fixed version adds a special tag\nobject to the `request`, and also to the `response`.  Now if you re-run\nthe test by running the server, sending it some requests with `ab`, and\nthen generate a heap snapshot, you can easily see that you're leaking\nrequests and not response, by searching on the classes named `Tag`...\n\n\n\n[1]: http://pmuellr.github.io/slides/2015/11-debuggable-javascript/index.html\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmuellr%2Fmaking-your-javascript-debuggable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmuellr%2Fmaking-your-javascript-debuggable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmuellr%2Fmaking-your-javascript-debuggable/lists"}