11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst { Console } = require('console'); 41cb0ef41Sopenharmony_ciconst { Writable } = require('stream'); 51cb0ef41Sopenharmony_ciconst async_hooks = require('async_hooks'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci// Make sure that repeated calls to console.log(), and by extension 81cb0ef41Sopenharmony_ci// stream.write() for the underlying stream, allocate exactly 1 tick object. 91cb0ef41Sopenharmony_ci// At the time of writing, that is enough to ensure a flat memory profile 101cb0ef41Sopenharmony_ci// from repeated console.log() calls, rather than having callbacks pile up 111cb0ef41Sopenharmony_ci// over time, assuming that data can be written synchronously. 121cb0ef41Sopenharmony_ci// Refs: https://github.com/nodejs/node/issues/18013 131cb0ef41Sopenharmony_ci// Refs: https://github.com/nodejs/node/issues/18367 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciconst checkTickCreated = common.mustCall(); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciasync_hooks.createHook({ 181cb0ef41Sopenharmony_ci init(id, type, triggerId, resource) { 191cb0ef41Sopenharmony_ci if (type === 'TickObject') checkTickCreated(); 201cb0ef41Sopenharmony_ci } 211cb0ef41Sopenharmony_ci}).enable(); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciconst console = new Console(new Writable({ 241cb0ef41Sopenharmony_ci write: common.mustCall((chunk, encoding, cb) => { 251cb0ef41Sopenharmony_ci cb(); 261cb0ef41Sopenharmony_ci }, 100) 271cb0ef41Sopenharmony_ci})); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_cifor (let i = 0; i < 100; i++) 301cb0ef41Sopenharmony_ci console.log(i); 31