Skip to content

Instantly share code, notes, and snippets.

@agreatfool
agreatfool / messagepack_performance.js
Created April 7, 2016 06:40
Compare the performance of two javascript message pack implementation: "msgpack5" & "msgpack-lite"
"use strict";
const msgpack = require('msgpack5')();
const msgpacklite = require("msgpack-lite");
const obj = {name: "jonathan", age: 29, gender: "male"};
const count = 100000;
const try5 = (act) => {
if (act === "encode") {
for (let i = 0; i < count; i++) {
// $ node -v
// v8.4.0
"use strict";
var v8 = require("v8");
console.log(v8.getHeapStatistics());
// { total_heap_size: 9437184,
// total_heap_size_executable: 3145728,
// total_physical_size: 6928200,
// $ node -v
// v8.4.0
// node --max-old-space-size=8192
"use strict";
var v8 = require("v8");
console.log(v8.getHeapStatistics());
// { total_heap_size: 9437184,
// total_heap_size_executable: 3145728,
--log_gc (Log heap samples on garbage collection for the hp2ps tool.)
type: bool default: false
--expose_gc (expose gc extension)
type: bool default: false
--max_new_space_size (max size of the new generation (in kBytes))
type: int default: 0
--max_old_space_size (max size of the old generation (in Mbytes))
type: int default: 0
--max_executable_size (max size of executable memory (in Mbytes))
type: int default: 0
#!/usr/bin/env node
// $ node -v
// v8.4.0
/**
Debug输出信息的查看,使用:
DEBUG=MEM:* node xxx.js
查看内存输出日志:
DEBUG=MEM:ReportMemory node ...
$ node --expose-gc --trace-gc --trace-gc-verbose ./cases/leak-and-gc.js --normal
[44972:0x103000000] Fast promotion mode: false survival rate: 57%
[44972:0x103000000] 60 ms: Scavenge 3.0 (5.5) -> 2.7 (6.5) MB, 1.2 / 0.0 ms allocation failure
[44972:0x103000000] Memory allocator, used: 6656 KB, available: 1459712 KB
[44972:0x103000000] New space, used: 581 KB, available: 425 KB, committed: 2048 KB
[44972:0x103000000] Old space, used: 778 KB, available: 0 KB, committed: 1024 KB
[44972:0x103000000] Code space, used: 1180 KB, available: 1 KB, committed: 1536KB
[44972:0x103000000] Map space, used: 201 KB, available: 0 KB, committed: 512 KB
[44972:0x103000000] Large object space, used: 0 KB, available: 1459191 KB, committed: 0 KB
[44972:0x103000000] All spaces, used: 2741 KB, available: 1459617 KB, committed: 5120KB
#!/usr/bin/env node
// node --expose-gc --trace-gc cases/leak-and-gc.js --normal | node cases/pipe-gc-parser.js
// node --expose-gc --trace-gc-nvp cases/leak-and-gc.js --normal | node cases/pipe-gc-parser.js
"use strict";
const readline = require("readline");
const GcParser = require("v8-gc-log-parser");
$ node -v
v8.4.0
$ node --v8-options | grep gc
--gc_global (always perform global GCs)
--gc_interval (garbage collect after <n> allocations)
--retain_maps_for_n_gc (keeps maps alive for <n> old space garbage collections)
--trace_gc (print one trace line following each garbage collection)
--trace_gc_nvp (print one detailed trace line in name=value format after each garbage collection)
--trace_gc_ignore_scavenger (do not print trace line after scavenger collection)
--trace_gc_verbose (print more details following each garbage collection)
@agreatfool
agreatfool / compiled.d.ts
Last active February 6, 2018 07:48
Static codes generated by protobuf.js
import * as $protobuf from "protobufjs";
/** Namespace com. */
export namespace com {
/** Namespace book. */
namespace book {
/** Properties of a Book. */
interface IBook {
@agreatfool
agreatfool / book_grpc_pb.d.ts
Created February 6, 2018 07:49
Codes generated by grpc-tools
// package: com.book
// file: book/book.proto
import * as grpc from "grpc";
import * as book_book_pb from "../book/book_pb";
interface IBookServiceService extends grpc.IMethodsMap {
getBook: IGetBook;
getBooksViaAuthor: IGetBooksViaAuthor;
getGreatestBook: IGetGreatestBook;