Overtime is Shameful

Lately I've been thinking about the differences in working culture between America and Japan, and I came across the blog of Eiji Sakai (Japanese), who is, according to his blog, a software engineer and with a CPA from an American university and an interest in economics, culture, and technology.  His articles about the differences in Japanese and western business cultures written from the perspective of a Japanese person who has apparently studied and worked abroad is particularly interesting to me, so I started reading and translating some of his articles.  The first article I translated is called "Overtime is Shameful" (残業は恥だ), and I'm posting my translation here.

"Overtime is Shameful"

"If the concept of extreme overtime work were to disappear from Japanese companies, just that alone would surely make the Japanese people much happier. If overtime disappeared from Japanese companies, I myself would consider once again working for one.

Let's take a look at the way people work in western companies where, unlike Japan, there is almost no extreme overtime.

Managers will assign work to each of their subordinates and manage progress.The subordinates will do only the work in the scope that has been assigned to them by their boss. If your own work is done, then you can go home at a regular time, but if it is not finished this results in overtime. Even if the person sitting next to you is doing overtime, that’s someone else's work and thus not your responsibility, so you can still go home early.

In this kind of environment, if somebody is consistently doing overtime, this means that the boss is not correctly estimating the ability of his or her subordinate. So the boss will usually ask his subordinate why he or she is doing so much overtime, and then will redistribute the workload in a manner such that all of his or her subordinates can go home at a reasonable time.

What about Japan? In Japan the boss tends not to give detailed instructions to their subordinates. At departmentwide meetings, the boss will present broad objectives. And the boss will suggest broad roles for each team member, but these are not absolute. It is expected that the team members will talk to each other and decide how to adjust the amount of work each member has appropriately.

In other words, in Japan they don't clearly delineate the work by saying "Okay this specific subset of the work is my responsibility." In this situation, it's hard even if just one person is doing overtime for anyone to go home early. Perhaps some small part of the work that is causing your teammate to do overtime is your responsibility. If that's the case, then the appropriate action is to stay and do overtime yourself to help that person. This means that, when the areas of responsibility are not clearly defined, there is the possibility that everyone's work will increase to no end.

So, how can we decrease the amount of overtime in Japanese companies? This is a difficult question. The only way that I can think of, is to make the division of work clear as they do in western companies, and thus reduce this "social overtime". However the Japanese are an ingenious people when it comes to making it ambiguous where responsibility lies (for example, it's typical for the anonymous culture of the Internet to be criticized in an anonymous article in a newspaper). So, the tough part is really whether this ideal is actually possible or not.

It's probably also important to have an attitude that recognizes that work is just work, and a job is just a job. Work is a public thing, and not a part of yourself. Because Japanese workers feel too strongly that their work is a part of their character or individuality, there are times when it's hard for them to draw the line between public and private life. Work is certainly important, but at the same time it's just work. Exactly what work is more important than your own family or friends? When you fall ill, who's going to be the one to come running to help? Will it be your job? Or will it be your family?

When discussing the reduction of overtime, usually what is emphasized is the effort of the person doing the overtime, but essentially the reduction of overtime is their responsibility of that person's manager. Here, the person who's in the wrong is the boss that failed to plan the work appropriately. Perhaps even the Japanese government could start a propaganda campaign with the slogan "the subordinates overtime is the bosses shame." It should be taken as a given that career bureaucrats in the Japanese government departments should themselves get rid of extended overtime."

NEWSFLASH: Snowboarding is awesome

I'm from Massachusetts.  I grew up tolerating the cold and snow, but sometime during the windy winters at college on a campus laid out with a cruel, long walk from dorms to academic buildings through many wind tunnels, I sort of started to hate the cold.

But I understand now why cold weather exists:

SNOWBOARDING.

I went for the first time this month when some people invited me for work, and now I don't want to stop.  I even bought some gear:

It's a little bright, but when else do you get to wear interesting colors like that?  

I also started going with Tokyo Snow Club, their trips are pretty fun.

Pool Allocator

Another useful memory algorithm is a pool allocator, which allocates lots of small blocks of memory of the same size.  Often times in programming games (and other applications) there are times where you need to allocate small chunks for same-sized items such as matrices, or multiple instances of the same object.  Obviously a pool allocator is the natural fit.  My implementation is below. 

--> Open PoolAllocator.cpp in a new window <--

The code above is hosten on Google Code, and you can comment by double clicking anywhere, or by clicking in the left hand margin on the little speech balloon plus icon. You need to be signed in with a google account.  Please comment and tell me if my code sucks!

Implementing a stack allocator isn't hard, but there is one important memory saving trick I'll discuss below:

  1. When creating the pool, preallocate a large block of memory, the size of which is a multiple of the size of the separate pool elements.
  2. Add each of the free elements to a linked list.
  3. When someone wants to use a block, pop one off the free list and return it to the user.
  4. When a block is freed, add it back to the free list.
  5. When deleting the pool, assert that the number of free elements is equal to the pool size divided by the size of an individual element.

That part is easy.  But we have to consider where we will get memory for the linked list to track the free elements.  Or do we?  We have all this free space in each of the free elements, why not put it to good use?

NOTE: The one caveat here is that the size of each element in the list must be larger than sizeof(void*)

To track the free items in the free list itself we do the following.

  1. When creating the pool, after allocating the memory, starting with the beggining of the list, write the address of the next free block at the start of the current block.
  2. When providing a block to the user, return the start of the list, but not before setting the pointer to the start of the list to the next block.
  3. When returning a block to the free list, write the address of the start of the free list into the start of the newly free block, and set the start of the free list to the newly freed block's address.

Remember that when using the memory of the free block itself as the pointer to the next block, the equivalent to 

mFreeListStart = mFreeListStart->next;

Becomes:

mFreeListStart = (u32*)*mFreeListStart;

Where mFreeListStart is a u32* to the start of memory of the first element in the list,

next is a u32* to the next element,

and  u32 is a 32-bit unsigned integer type.

Stack Allocator

So I said I was going to start working on my game engine project, and I know it seems like I've been doing a whole lot of nothing, but I've been working this whole time!  ...Well some of this whole time.

Working on what?  On Memory!

I've written a few different memory algorithms now, but I'll start with the simplest: a Stack Allocator.

--> Open StackAllocator.cpp in a new window <--

The code above is hosten on Google Code, and you can comment by double clicking anywhere, or by clicking in the left hand margin on the little speech balloon plus icon. You need to be signed in with a google account.  Please comment and tell me if my code sucks!

A stack allocator is useful in games because many games allocate memory for levels in a stack like manner.  When a new game level is loaded, the memory for all the textures and meshes etc is loaded at once, and then nothing more is allocated during the duration of the level.  When the level is unloaded, all of the memory is freed.  A stack memory allocator is perfect for this sort of application.

Implementing a stack allocator is pretty simple:

  1. In the constructor, malloc a block of memory to use as the stack, and set it as the base of the stack and as the current top (ensuring it's not NULL).
  2. When memory is requested from the stack, store the address of the current top to return, and then move the current top up by the size requested.
  3. When freeing, you just set the current top back to the marker passed to the freeToMarker function.
  4. Clear the stack by setting the current top back to the base of the stack.
  5. When deleting the whole stack, you can ensure all memory has been freed by asserting that the current top is the same memory address as the base

The next write up I believe will be Pool Allocators.